Set up a Linux server allows remote access to MySQL

MySQL open Remote Access:  Log mysql service on linux systems.

- root user name is 
[root @ localhost ~] # MySQL -u root -p 
the Enter password: - Enter the password

Create a remote connection to the MySQL user:

- Create a user, password and purview first roo t after the username @ host for the application, '%' means that all computers can access, which is the second root password 
mysql> GRANT ALL PRIVILEGES ON * * . the TO 'root'@'192.168.0.2' the IDENTIFIED BY 'the root' the WITH the GRANT the OPTION;                  
Query the OK, 0 rows affected (1.57 sec) 

- immediate effect 
MySQL> the flush privileges; 
Query the OK, 0 rows affected (0.00 sec)

 

Database User Action:

-- 使用 mysql 库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

-- 查看用户

  mysql> select host,user from user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | %         | lys              |
  | %         | mcAdmin          |
  | %         | root             |
  | %         | zcbox            |
  | localhost | debian-sys-maint |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | phpmyadmin       |
  +-----------+------------------+
  8 rows in set (0.00 sec)

  - change user permissions:

  mysql> update user set host = 'localhost' where user = 'mcAdmin';
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1 Changed: 1 Warnings: 0

  -- delete users:  

  mysql> delete from user where user = 'mcAdmin';
  Query OK, 1 row affected (0.00 sec)

  

- effective immediately 
 MySQL> flush privileges; 
 Query the OK, 0 rows affected (0.00 sec)
Visible user is actually a table, its operation and normal operation mysql no different. 

At this time, the older version of mysql, already allow external access to the database can

but in mysql5.7, the above operation may still not allow you to access outside the local database server, MySQL 5.7 because the default configuration file also allows only local access
so it to modify the configuration files MySQL
generally in the path /etc/mysql/mysql.conf.d/mysqld.cnf
open this file by vi / vim / gedit like editor

commented bind-address = 127.0.0.1
then sudo service mysql restart restart mysql

Get!

View Port: 

mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)

3306 looks like there may be a problem of the port, the configuration file also see the line port = 3306, but did not impact on the first matter;
met to resolve

Guess you like

Origin www.cnblogs.com/wangtong111/p/11201734.html