How to initialize the root password for MySQL

Source: Internet
Author: User

This article mainly describes how to initialize the root password of MySQL and the correct operation steps to allow remote access and the actual application code, if you are interested in the actual operations that allow remote access to MySQL, the following articles will satisfy your curiosity.

MySQL has no password by default. Enter MySQL-u root to enter MySQL.

1. MySQL initializes the root password

Enter the MySQL database

 
 
  1. view sourceprint?1 mysql>update user set password=PASSWORD(‘123456’) where User='root';  

2. To allow remote access to MySQL, you can use the following three methods:

A. Change the table.

 
 
  1. view sourceprint?1 MySQL -u root –p   
  2. MySQL>use MySQL;   
  3. MySQL>update user set host = '%' where user = 'root';   
  4. MySQL>select host, user from user;   

B. Authorization.

For example, you want the root user to use 123456 to connect to the MySQL server from any host.

 
 
  1. view sourceprint?1 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;  

If you want to allow jack to connect to the mysql server from a host with ip address 10.10.50.127 and use 654321 as the password

 
 
  1. view sourceprint?1 mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;  

2 mysql> FLUSH RIVILEGES

C: run the following command on the machine where mysql is installed:

View sourceprint? 1 // enter the MySQL server

2 d: \ mysql \ bin \> mysql-h localhost-u root

3 // grant data access permissions to any host

4 mysql> grant all privileges on *. * TO 'root' @ '%' WITH GRANT OPTION

5 // make the modification take effect

6 mysql> FLUSH PRIVILEGES

7 // exit the MySQL server

8. mysql> EXIT

The above content describes how to initialize the root password for MySQL and allow remote access. I hope you will gain some benefits.
 

The above content describes how to initialize the root password for MySQL and allow remote access. I hope it will help you in this regard.

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.