Ubuntu 安装mysql,ubuntu安装mysql


如果在机器以前有安装过Mysql,在重新安装Mysql前最好把之前的内容卸载干净,不然有可能出现不可预见的问题。

/**
 * @author jenkiHuang
 * @email jenkiHuang@qq.com
 * @version 20150402
 * /

//删除已有的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

//安装 mysql
sudo apt-get install mysql-server

//登录mysql
mysql -uroot -p

//重启mysql
sudo service mysql restart

 

执行上面命令后,可以在本地实现登录mysql数据库。但是如果是项目组多人开发,必定会有多人连接数据库,这样就必须修改数据库的配置文件。

//远程连接mysql
sudo vi /etc/mysql/my.cnf

//找到bind-address = 127.0.0.1
//注释掉这行,如:#bind-address = 127.0.0.1
//或者改为: bind-address = 0.0.0.0
//允许任意IP访问;或者自己指定一个IP地址。

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

//授权用户能进行远程连接
grant all privileges on *.* to root@"%" identified by "123456" with grant option;

//刷新权限信息,设置马上生效
flush privileges;

转载:http://www.jenkihuang.com/experience/2015/04/ubuntu-install-mysql.html

相关内容