Sharing Ubuntu under how to set up a MySQL remote connection

Source: Internet
Author: User
Tags bind flush

1, MySQL installation after the password can not be landed problem

Then you need to go into the/etc/mysql directory and check the username and password inside, and then

sudo vim debian.cnf

Use the username and password in this file to enter MySQL, if the username in debian.cnf is debian-sys-maint, then:

Mysql-u debian-sys-maint-p


Press ENTER, when you need to enter a password, copy the password in the DEBIAN.CNF (do not manually input, because error prone).
A prompt such as mysql> appears in the terminal:

Use MySQL
Show tables;//View the tables in the MySQL database and see a user table.
SELECT * from user;//to see if there is a root user in this table, if:
Update user Set Password=password ("root") whereuser= "root";//change the password for the root user to enter MySQL.
Flush privileges;

Quit quit MySQL.
and use

Mysql-u Root-proot


Re-login MySQL can be.
If there is no root user in the user table: with the grant command
Grant all privileges on *.* to root@localhost identified by ' 123 '
Where *.* represents all the tables in all databases, that is, the password that database name.your table ' 123 ' is represented as the root user.
Flush privileges;
SELECT * from user, and check to see if user has root in this table. If there are representations added successfully.
Quit quit MySQL.

Mysql-u root-p 123 into MySQL.

2. Configure Remote connection



vim/etc/mysql/my.cnf Find bind-address = 127.0.0.1

Comment out this line, such as: #bind-address = 127.0.0.1

or instead: Bind-address = 0.0.0.0

Allow arbitrary IP access;

Or specify an IP address yourself.

Restart Mysql:sudo/etc/init.d/mysql restart
Ii

Authorized users to connect remotely

Grant all privileges on *.* to root@ '% ' identified by ' password ' with GRANT option;

Flush privileges;
The first line of command is interpreted as follows, *.*: The first * represents the database name, and the second * represents the table name. This means that all the tables in the database are licensed to the user. Root: Grant root account. "%": Authorized User IP can be specified, where any IP address can access the MySQL database. "Password": Assign the password corresponding to the account, where the password is replaced by your MySQL root account password.

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.