In this post, we learn how to setup mysql database in our local machine, then create a local database to practice development.
If you don’t have MySQL database in your local environment, then download and install MySql right version for your operating system
Once you have installed mysql, go to command prompt and execute the following command
CREATE DATABASE myDatabaseName;
Create a username and password for newly created database
GRANT ALL PRIVILEGES ON *.* TO 'username123'@'localhost' IDENTIFIED BY 'password123';
Working in command window you may not feel comfortable; alternatively you can download any PHP client or install XAMPP and start using MyPhpAdmin for all mysql database related work, most of the php mysql develop this way.
Once you have successfully installed XAMPP on your local machine, then you should be able to access following php admin interface this way
http://localhost:8080/phpmyadmin/
Now you need to login with your root username=(root) and password, if you don’t know your password , you can reset the root password of myphpadmin
After logging into myphpadmin, you will see all the database on your left panel, select the database you want to work with, create, alter objects ..have fun
you can also create mysql database from sql file by importing into current server.
in myphpadmin => import => browse SQL file => go
if you have ready database script and want to setup a local database to testing or enhancement, you can simply import the script into local serve and execute the script database will be set within a minute.
Create database user, change user password in mysql 8
SELECT User, Host FROM mysql.user; //Create new user CREATE USER 'username1'@'localhost' IDENTIFIED BY 'password1'; // update user password ALTER USER 'username1'@'localhost' IDENTIFIED BY 'password1';
When using mysql 8 from python 3.7 and above you may need to change the plugin in connectionstring, even in mysql table you need to update the plugin to native, use the query below
ALTER USER 'username1'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password1';
by the time you use this, php or mysql version may change, but the funda will remain same.