Log in
Log in to your cloud server.
Log in to MySQL by running the following command:
mysql -u root -p
You are prompted for your MySQL root password (note that this is not the same as the Cloud Server root password).
Create a new user
You can create a new user and set a password for the user at the same time, as shown in the following example command, which creates a user with the username test:
CREATE USER ‘test’@’localhost’ IDENTIFIED BY ‘newpassword’;
Next, you need to flush the privileges, which reloads the user table in MySQL. You must perform this step each time you add or edit a user.
The following example shows the command that you use to flush privileges:
FLUSH PRIVILEGES;
Set permissions for the new user
At this stage, your new user (test) has no permissions set and can’t do anything. You might want to start setting permissions by assigning SELECT (read-only) permissions on all of the available databases. You can grant select permissions by running the following command:
GRANT SELECT ON * . * TO ‘test’@’localhost’;
Permissions – All
Create a new database and allow test to have full access to it so that they can create, read, update, and delete records, as shown in the following example:
CREATE DATABASE mytestdb;
Now we have the database and the user, we can assign the privileges:
GRANT ALL PRIVILEGES ON `mytestdb` . * TO ‘test’@’localhost’;
Note: You must include the backticks that surround the database name.
This is the type of permission that you might want to use when you are setting up a user and a database for a web application. The user doesn’t need to access any other database.
Flush the privileges by running the following command:
FLUSH PRIVILEGES;
Log in as the new user
To verify that the permissions that you set work properly, log in to MySQL as the new user by running the following command:
mysql -u test -p
When you are prompted, enter the password for the test user.
After you are logged in as the test user, try to create a new database by running the following command:
CREATE DATABASE mytestdb2;
The following error message displays:
ERROR 1044 (42000): Access denied for user ‘test’@’localhost’ to database ‘mytestdb2’
This error occurs because the test user only has ALL PRIVILEGES for the ‘mytestdb’ database, and SELECT privileges for everything else.
Drop a user
If you need to drop a user, the process is similar to dropping a database. The following example shows how to drop the test user:
DROP USER ‘test’@’localhost’;
Reseting wp users
mysql -u root -p
(Logs in to MySQL) Enter your password at the prompt.
“use name-of-database” (Selects your WordPress database)
“show tables LIKE ‘%users’;”
(Finds the WordPress user table)
“SELECT ID, user_login, user_pass FROM name-of-table-you-found WHERE user_login = ‘username‘;”
(Observe the encrypted password)
“UPDATE name-of-table-you-found SET user_pass=MD5(‘new-unencrypted-password‘) WHERE user_login = ‘username‘;”
(Updates the database with the encrypted password)
“SELECT ID, user_login, user_pass FROM name-of-table-you-found WHERE user_login = ‘username‘;”
(Confirm that it was changed)
“exit”
(Exits the MySQL client)
Login to WordPress using the username and password that you’ve altered.
Cant Find Mysql PDO driver
sudo apt-get --purge remove php-common
sudo apt-get install php-common php-mysql php-cli
Common Practice
mysql> CREATE DATABASE test_db;
mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Strong34S;#";
mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
mysql> FLUSH PRIVILEGES;
Leave A Comment?