ubuntu下安装mysql,并允许远程连接

安装卸载mysql

1,安装
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install php5-mysql(用于连接php和mysql)


查看mysql是否运行
ps aux | grep mysql

启动命令
/etc/init.d/mysql start

2.删除mysql

按顺序执行以下命令
sudo apt-get autoremove --purge mysql-server-5.0
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common

清理残留数据
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

                 

配置远程连接:

第一步:


1,mysql> use mysql;

2,mysql>    update user set host = ’%’ where user = ’root’;

3,mysql> select host,user,password from user;

4,在需要连接的服务器端查看用户权限:

show grants;

出现 如下

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*EA5FD23FAEE21132435461B733F64981454FD4AF' WITH GRANT OPTION

标示授权成功

授权用户能进行远程连接

   grant all privileges on *.* to root@"%" identified by "password" with grant option;(不需要执行,mysql已经帮你自动执行当修改为%的时候)

   flush privileges;
   第一行命令解释如下,*.*:第一个*代表数据库名;第二个*代表表名。这里的意思是所有数据库里的所有表都授权给用户。root:授予root账号。“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。“password”:分配账号对应的密码,这里密码自己替换成你的mysql root帐号密码。

   第二行命令是刷新权限信息,也即是让我们所作的设置马上生效。


第二步

vim /etc/mysql/my.cnf找到bind-address = 127.0.0.1
注释掉这行,如:#bind-address = 127.0.0.1

或者改为: bind-address = 0.0.0.0
允许任意IP访问;

或者自己指定一个IP地址。

再最后加上下面两句:

skip-external-locking
skip-name-resolve

重启 MySQL:sudo /etc/init.d/mysql restart

猜你喜欢

转载自alan0509.iteye.com/blog/2117705