Linux上安装MySQL(亲测详细实用版)
目录
问题1::2003 Can't connect to mysql server on 192.168.27.141
问题2:1130: Host '192.168.27.1' is not allowed to connect to this mysql server
一:上传安装包
安装包百度云下载地址
https://pan.baidu.com/s/1KQGjdEPe_Z6PLjfcugzIfA
二:MySQL的安装
1:卸载Linux上自带的MySQL
rpm -qa | grep mysql
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
2:解压安装包
tar -xvf MySQL-5.6.22-1.e16.i686.rpm-bundle.tar -C /training/MySQL5.25
tar -xvf MySQL-5.6.25-1.el6.x86_64.rpm-bundle.tar -C /training/MySQL5.25
3:安装服务端(64位,同Linux)
rpm -ivh MySQL-server-5.6.25-1.el6.x86_64.rpm
如果显示缺少依赖,需要安装依赖:
yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6
4:安装客户端
1: 安装rpm包
rpm -ivh MySQL-client-5.6.25-1.el6.x86_64.rpm
2:查看随机生成的密码
cat /root/.mysql_secret
3:以root用户登录
mysql -u root -p
然后输出随机的密码 VOYRZhKAyrVCwpGl
4:设置密码
set password=password('123456');
三:系统设置
Mysql服务加入到系统服务并自动启动操作:
chkconfig --add mysql
自动启动:
chkconfig mysql on
查询列表,程序是否启动成功:
chkconfig
四:常见连接报错处理
问题1::2003 Can't connect to mysql server on 192.168.27.141
解决方法:关闭防火墙
问题2:1130: Host '192.168.27.1' is not allowed to connect to this mysql server
解决方法:
原因是Linux上的mysql并没有开启远程访问方服务
1:给root用户的远程访问赋值,并设置密码为root
grant all privileges on *.* to 'root' @'%' identified by '你的root密码';
2:刷新权限
flush privileges;
3:防火墙打开3306端口
vi /etc/sysconfig/iptables
添加以下配置到该配置文件中
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status
4:测试成功