1、首先检测一下,mysql之前有没有被安装
命令:rpm -qa | grep mysql
2、删除mysql的命令: rpm -e --nodeps `rpm -qa | grep mysql`
3、在线安装mysql命令:yum -y install mysql-server
4、开启mysql服务:service mysqld start
5、把mysql服务加载到开机启动项:chkconfig mysqld on
6、初始化配置mysql服务
where is mysql_secure_installation
执行脚本/usr/bin/mysql_secure_installation(执行脚本会让你初始化数据库的密码等操作,注意)
7、登录mysql: mysql -u root -p 接下来输入密码登录mysql(密码在执行脚本mysql_secure_installation设置的)
8、mysql> select host, user, password from user; 显示你的用户权限,发现只能在localhost下连接mysql,不能远程连接
9、执行 Grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
‘123456‘ 为root用户的密码,我这里是给root用户远程连接权限,可以改为自己创建的用户
10、再次执行select host, user, password from user; 查询发现root权限新增 % 这就表示所有外在ip都可以通过root连接mysql
11、重启mysql就可以了
注意:防火墙关闭或者开放3306端口,不然连接不上