This tutorial explains how you can create MySQL user and database using command line.
First, we will update the system and install MySQL database.
We will update system and install MySQL database.
For CentOS/RHEL OS:
1 |
yum update -y && yum install mysql mysql-server -y && service mysqld start && chkconfig mysqld on && mysql_secure_installation |
Now follow these steps:
1 2 3 4 5 6 7 8 |
Enter current password for root (enter for none): # pritisnite Enter Set root password? [Y/n] # pritisnite Enter New password: # Ukucajte lozinku Re-enter new password: # Potvrdite lozinku Remove anonymous users? [Y/n] # pritisnite Enter Disallow root login remotely? [Y/n] # pritisnite Enter Remove test database and access to it? [Y/n] # pritisnite Enter Reload privilege tables now? [Y/n] # pritisnite Enter |
When you finished MySQL installation you can log in to MySQL:
1 |
mysql -u root -p |
Type MySQL root password.
Create database:
1 |
mysql> CREATE DATABASE mydatabase; |
Create new user and password:
1 |
mysql> CREATE USER 'mysqluser'@'localhost' IDENTIFIED BY 'UserPassword'; |
Add privileges to user mysqluser on database mydatabase and exit console:
1 2 3 |
mysql> GRANT ALL ON mydatabase.* TO 'mysqluser'@'localhost'; mysql> FLUSH PRIVILEGES; mysql> quit |
You can use this database (DB name, DB username and DB password) to install your CMS (WordPress, Joomla…) now.
You can also import database backup in your new database mydatabase and connect your application to database:
1 |
mysql -u mysqluser -p mydatabase < mysqldatabase.sql |
And type password for user mysqluser.