The most basic command of MySQL USES summary

  • 2020-11-25 07:37:59
  • OfStack

1. Connect MySQL(the best combination with PHP)

Format: -ES5en host address -u username -p user password

Example 1: Connect to MySQL on the local machine.

First open the DOS window, then enter the directory bin, and then type -ES15en-ES16en. When you enter, you will be prompted to enter the password. If you have just installed, the super user root does not have a password, so you can enter MySQL directly by pressing enter.

Example 2: Connect to MySQL on a remote host.

Assume that the remote host's IP is 110.110.110.110, the user name is root, and the password is abcd123. Type the following command:

 -h110.110.110.110 -uroot -pabcd123

(Note :u and root do not need space, and there is one other)

3. Exit MySQL: exit (enter).

2. Change your password

Format: ES40en-ES41en Username -p Old password password New password

Example 1: Add a password to root ab12. First enter the directory bin under DOS, and then type the following MySQL command:

admin -uroot -password ab12

Note: Since root did not have a password at the beginning, one item of the old -ES55en password can be omitted.

Example 2: Then change the password of root to djg345, command:

admin -uroot -pab12 password djg345

3. Add new users

(Note: unlike the above, the following commands in the MySQL environment are followed by a semicolon as the end of the command)

Format: grant select on database.* to username @ Login host identified by \" Password \"

Example 1: Add a user test1 whose password is abc, so that he can log in on any host and have the permission to query, insert, modify and delete all databases.

First connect to MySQL for the root user, then type the following command:

grant select,insert,update,
  delete on *.* to test1@\"%\" Identified by \"abc\";

But the increase in test1 is 10 points dangerous. You think that if someone knows the password for test1, they can log into your MySQL database from any computer on internet and do whatever they want with your data. See Example 2 for a solution.

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 access the data directly from the internet library, only through MySQL web page to access the host.

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 one more command to cancel the password.

grant select,insert,update,delete on mydb
  .* to test2@localhost identified by \"\";

Above described login, add user, password change and other issues, I hope to help you with your study.


Related articles: