ubuntu 安装mysql

1. 安装mysql服务器、客户端及客户端开发工具

sudo apt install mysql-server mysql-client libmysqlclient-dev

 

2.设置远程访问mysql

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

注释掉bind-address = 127.0.0.1这一行,保存退出编辑

mysql -u root -p

进入mysql服务,输入如下命令允许任何机器访问mysql服务器:

法一:修改权限法:

mysql> grant all privileges on *.* to 'root'@'%' identified by 'mypassword' with grant option; 
mysql> flush privileges;

 

法二:修改表法:

mysql> select host,user from user;

 

结果如下:

mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.01 sec)

将user为root的用户的host改为%:

mysql> update user set host='%' where user='root';

再次查询结果如下:

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

使修改生效:

mysql> flush privileges;

 

3.使用mysql客户端gui工具(navicat)连接mysql服务

 

posted @ 2018-08-24 11:31  pry_up  阅读(195)  评论(0编辑  收藏  举报