yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
2.下载mysql(https://dev.mysql.com/downloads/mysql/5.6.html#downloads)
wget https://cdn.mysql.com//Downloads/MySQL-5.5/MySQL-5.5.58-1.el6.x86_64.rpm-bundle.tar
2.将下载下来的tar文件解压
tar -xvf MySQL-5.5.58-1.el6.x86_64.rpm-bundle.tar
3.安装顺序依次安装:
yum install MySQL-shared-5.5.58-1.el7.x86_64.rpm
yum install MySQL-server-5.5.58-1.el6.x86_64.rpm
yum install MySQL-client-5.5.58-1.el6.x86_64.rpm
yum install MySQL-devel-5.5.58-1.el6.x86_64.rpm
4.启动服务:
service mysql start
5.查看服务运行状态:
service mysql status
出现如上状态,则安装成功.
注:如上安装步骤,默认登录用户为root,密码为空.
修改密码:
mysqladmin -u用户名 -p旧密码 password 新密码
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladmin
mysqladmin -u root password "newpass"
如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接编辑user表
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丢失root密码的时候,可以这样
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
允远程连接:
use mysql;
update user set Host='%' where Host='127.0.0.1' and User='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密码' WITH GRANT OPTION;
exit;
service mysql stop
service mysql start