This article provides you with information on how to manage MySQL on CentOS 7 server using root.
First, we’ll log in to the MySQL server from the command line with the following command:
mysql -u root -p
In this case, I’ve specified the user root with the -u flag and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.
You should now be at a MySQL prompt that looks very similar to this:
View All MySQL Databases
To view a list of databases simply issue the following command:
Your result should be similar to this:
mysql> SHOW DATABASES;
| Database |
| information_schema |
| mysql |
| test |
4 rows in set (0.00 sec)
Update a Database user password in MySQL
We’ll update the password for all MySQL users with the name root. Be sure to replace your_new_password with the actual new password:
update user set password=PASSWORD('your_new_password') where User='root';
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root.
Finally, reload the privileges:
Delete a Database in MySQL
It only takes one simple command to delete a database in MySQL, but BEWARE; dropping a database can not be undone! The command is as follows:
DROP DATABASE tutorial_database;
If a database with the name tutorial_database does not exist, then you’ll receive this error:
ERROR 1008 (HY000): Can't drop database 'tutorial_database'; database doesn't exist
To avoid seeing this error use the following command instead:
DROP DATABASE IF EXISTS tutorial_database;
The above command will only drop the database tutorial_database if a database of that name exists.