1. 下载mysql的repo源
$
wget http://repo
.mysql.com
/mysql-community-release-el7-5
.noarch.rpm
2.
安装mysql-community-release-el7-5.noarch.rpm包
$
sudorpm -ivh mysql-community-release-el7-5.noarch.rpm
3.
安装mysql
$
sudoyum
install
mysql-server
4.
重置密码
$
mysql -u root
登录时有可能报这样的错:ERROR
2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户
$
sudochown
-R openscanner:openscanner
/var/lib/mysql
$
service mysqld restart
6接下来登录重置密码:(注意分号)
$
mysql -u root
|
$
mysql > update user set
password=password(
'123456'
) where user=
'root'
;
$
mysql > exit
;
7.
开放3306端口
$
sudovim
/etc/sysconfig/iptables
添加以下内容:-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
8.添加远程访问权限
mysql>
use mysql;
mysql>
desc user;
//为root添加远程连接的能力
mysql>
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
//设置root用户密码
mysql>
update user set Password = password('123456') where User='root';
mysql>
select Host,User,Password from user where User='root';
mysql>
flush privileges;
mysql>
exit
//登陆
$
mysql -u root@123456