MYSQL basic connection MYSQL change password add user

  • 2020-05-07 20:33:08
  • OfStack

1. Connect MYSQL.
Format: mysql-h host address -u username -p user password
1. Example 1: connect to MYSQL on the local machine.
First open the DOS window, then enter the directory mysqlbin, and then type the command mysql-uroot-p, enter the prompt you enter the password, if you just installed MYSQL, the super user root is not password, so directly enter MYSQL, MYSQL prompt is: mysql >
2. Example 2: MYSQL connected to a remote host. assumes that the IP of the remote host is: 110.110.110.110, the user name is root, and the password is abcd123. Then type the following command:

mysql -h110.110.110.110 -uroot -pabcd123
(note :u and root do not need to add space, and the others are the same)
3, exit MYSQL command: exit (enter)
2. Change your password.
Format: mysqladmin-u username -p old password password new password
Example 1: give root the password ab12. First enter the directory mysqlbin under DOS and then type the following command
mysqladmin -uroot -password ab12
Note: since root did not have a password at the beginning, the old password 1 item of -p can be omitted.
2. Example 2: change the password of root to djg345.
mysqladmin -uroot -pab12 password djg345
Add new users. (note: unlike above, the following commands are followed by a semicolon as the end of the command because they are in the MYSQL environment.)
Format: grant select on database.* to username @ login host identified by "password"
Example 1, add one user test1 password as abc, so that he can log in on any host, and all databases have the right to query, insert, modify, delete. First use root to connect to MYSQL, and then type the following command:
grant select insert, update, delete on *. * to test1 @ "%" Identified by "abc";
If someone knows the password of test1, he can log into your mysql database from any computer on internet and do whatever he wants with your data. The solution is shown in example 2.
Case 2, add 1 user test2 password for abc, let he can login on localhost only, and can be conducted on database mydb query, insert, modify, delete operations (localhost refers to the local host, namely MYSQL database to the host), so that users use know test2 password, he cannot directly access the database from the internet, only through web MYSQL hosts to access the page.
grant select insert, update, delete on mydb. * to test2 @ localhost identified by "abc";
If you don't want test2 to have a password, you can type another command to cancel the password.
grant select insert, update, delete on mydb. * to test2 @ localhost identified by "";


Related articles: