How can I operate the MySQL database correctly?

Source: Internet
Author: User

The following articles mainly introduce the correct usage of the MySQL database, including the actual operation steps for connecting to the MySQL database, the actual operation process for changing the password, and the actual operations for adding new users, the following describes the specific content of the article. I hope you will find some gains.

1. Connect to MySQL.

Format: MySQL-h host address-u user name-p User Password

1. Connect to the MySQL database on the local machine.

First, open the DOS window, enter the MySQL \ bin directory, type the MySQL-u root-p command, and press enter to prompt you to enter the password. note that there can be space or space before the user name, but there must be no space before the password; otherwise, you can re-enter the password.

If you have just installed MySQL, the Super User root has no password, so press enter to enter the MySQL database. The MySQL prompt is: MySQL>

2. Connect to MySQL on the remote host. Assume that the IP address of the remote host is 110.110.110.110, the user name is root, and the password is abcd123. Enter the following command:

MySQL-h110.110.110.110-u root-p 123; Note: Do not add spaces between u and root. The same applies to others)

3. exit MySQL command: exit and press Enter)

2. Change the password.

Format: MySQLadmin-u username-p old password New password

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

 
 
  1. MySQLadmin -u root -password ab12 

Note: because the root account does not have a password at the beginning, the old-p password can be omitted.

2. Change the root password to djg345.

 
 
  1. MySQLadmin -u root -p ab12 password djg345 

3. Add new users.

Note: Unlike the above, the following commands in the MySQL database environment are followed by a semicolon as the command Terminator)

Format: grant select on database. * to username @ login host identified by "password"

1. Add a user named "test1" with the password "abc" so that he can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MySQL, and then type the following command:

 
 
  1. grant select,insert,update,delete on *.* to [email=test1@”%]test1@”%[/email]” Identified by “abc”; 

However, the added users are very dangerous. If someone knows the password of test1, then he can log on to your MySQL database on any computer on the internet and do whatever he wants for your data. See solution 2.

2. Add a user named "test2" with the password "abc" so that the user can only log on to localhost and query, insert, modify, and delete the Database "mydb". localhost indicates the local host, that is, the host of the MySQL database ),

In this way, the user knows the password of test2 and cannot directly access the database from the internet. He can only access the database through the web page on the MySQL database host.

 
 
  1. grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by “abc”; 

If you do not want test2 to have a password, you can run another command to remove the password.

 
 
  1. grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by “”; 

The above content is an introduction to the usage of the MySQL database. I hope you will gain some benefits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.