Three essential elements for MySQL beginners

Source: Internet
Author: User
Tags php and mysql

The following articles mainly introduce the guide for beginners of MySQL, including how to correctly connect to MySQL (the best combination of PHP and MySQL ), the following describes how to change the password and add new users.

MySQL beginner's Guide 1. Connect to MySQL (the best combination with PHP)

Format: MySQL (best combination with PHP)-h host address-u user name-p User Password

1. Example 1: connect to MySQL on the local machine (the best combination with PHP ).

First, open the DOS window, enter the directory MySQL (the best combination with PHP) bin, and then enter the command MySQL (the best combination with PHP)-uroot-p, after you press enter, you are prompted to enter the password. If you have just installed MySQL (the best combination with PHP), the Super User root has no password, so press enter to enter MySQL (the best combination with PHP). The prompt for MySQL (the best combination with PHP) is: mySQL (the best combination with PHP)>

2. Example 2: connect to MySQL on the remote host (the best combination with PHP ). 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 (best combination with PHP)-h110.110.110.110-uroot-pabcd123

Note: u and root do not need to add spaces. The same applies to others)

3. exit MySQL (the best combination with PHP) command: exit and press Enter)

Guide for beginners of MySQL II. Change the password

Format: MySQL (best combination with PHP) admin-u username-p old password New password

1. Example 1: Add a password ab12 to the root user. First, enter the MySQL directory (the best combination with PHP) bin in DOS, and then type the following command

MySQL (best combination with PHP) admin-uroot-password ab12

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

2. Example 2: Change the root password to djg345.

MySQL (best combination with PHP) admin-uroot-pab12 password djg345

MySQL beginner's guide 3. Add new users

Note: Unlike the above, the following commands are used in the MySQL (best combination with PHP) environment, so a semicolon is followed as the command Terminator)

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

Example 1: Add a user named "test1" with the password "abc" so that the user 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 (the best combination with PHP), and then type the following command:

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

However, the User Added in Example 1 is very dangerous. If someone knows the password of test1, then he can log on to your MySQL database (the best combination with PHP) on any computer on the internet and do whatever he wants for your data. For the solution, see Example 2.

Example 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 on which the MySQL (best combination with PHP) database is located. In this way, the user knows the password of test2 and cannot directly access the database from the internet, you can only access the web pages on the MySQL (best combination with PHP) host.

 
 
  1. grant select,insert,update,delete on mydb.* to test2@localhost 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 test2@localhost identified by "";  

Next let's take a look at the database operations in MySQL (the best combination with PHP. Note: you must first log on to MySQL (the best combination of PHP and MySQL). The following operations are performed at the MySQL (the best combination of PHP and MySQL) prompt, each Command ends with a semicolon.

Related Article

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.