ubuntu配置mysql

1、安装mysql:

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

设置远程连接

远程登陆数据库的时候出现了下面出错信息:

  ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx',

  经过今天下午的反复纠结,关于MySql数据库无法远程连接的问题可以归结为以下几点:

  1). 没有授予相应的权限:

  例如,你想root使用123456从任何主机连接到mysql服务器。

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

  如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码

mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;

mysql>FLUSH RIVILEGES

  2). 修改mysql数据库中的user表使相应的用户能从某一主机登陆  

mysql -u root –p

mysql>use mysql;

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

mysql>select host, user from user;

  3). 防火墙禁止了3306端口,以iptable为例    

    vi /etc/sysconfig/iptables

    增加下面一行:

    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306-j ACCEPT  

    service iptables restart

    ps:  iptables设置

    1) 重启后生效 

    开启: chkconfig iptables on 

    关闭: chkconfig iptables off 

    2) 即时生效,重启后失效 

    开启: service iptables start 

    关闭: service iptables stop

  4). 修改MySQL的配置文件/etc/mysql/my.cnf,因为默认3306端口只允许本地访问的,注释掉这行

    #bind-address = 127.0.0.1

  然后重启Mysql,/etc/init.d/mysql restar

原文地址:https://www.cnblogs.com/mrwuzs/p/8028135.html