Install MySql in Ubuntu and connect _ MySQL on the Internet

Source: Internet
Author: User
Pure beginner tutorial. 1 installation mysqlapt-getinstallmysql-servermysql-clientlibmysqlclient15-dev installation process will prompt for the database root account to set a password, enter both sides of the password to 2, enter mysqlmysql-uroot-p pure novice tutorial.

1. install mysql
apt-get install mysql-server mysql-client libmysqlclient15-dev  

During the installation process, you will be prompted to set a password for the root account of the database. enter the two passwords.

2. enter

mysql  mysql -uroot -p 

3. reset the mysql User root password.

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";

4. create a new database proxy

create database proxy;

5. create user test with full operation permissions on the proxy database

grant all privileges on proxy.* to test@localhost identified by "testpwd";

6. allow the test user to log on to MySQL from any machine

grant all privileges on proxy.* to test@"%" identified by "testpwd"; 

7. log out of mysql

exit 

8. After mysql is installed, the default listening address is 127.0.0.1 and Port is 3306. You can run the following command to view the listening address and port:

netstat -ntulp

9. if you are listening for 127.0.0.1, the database cannot be connected from the Internet. In this case, you can modify the listening address to 0.0.0.0:

sudo vim /etc/mysql/my.cnf

Find bind-address = 127.0.0.1, change 127.0.0.1 to 0.0.0.0, save and exit

10. restart mysql to make the configuration take effect.

service mysql restart 

Now, you can remotely connect to the mysql database using MySql_Front or phpmyadmin. However, you can only remotely log on to the test account you just authorized. By default, the root account does not allow remote database logon. You can use either of the following methods to allow the root account to remotely log on to the database:

(1). change the table method.

It may be that your account is not allowed to log on remotely, but only on localhost. At this time, you only need to log in to mysql on the computer of localhost, and change the "host" entry in the "user" table in the "mysql" database to "%" from "localhost"

mysql -u root -pmysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;

(2). authorization method.

For example, if you want myuser to use mypassword to connect to the mysql server from any host:

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.3, and use mypassword as the password
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

If you want to prevent the root account from logging on to the mysql database remotely due to security concerns:

delete from user where user = 'root' and host = '%';select host, user from user;flush privileges;

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.