当前位置: > CentOS > CentOS教程 >

CentOS7安装MySQL5.6.28及其修改密码

时间:2017-02-28 13:29来源:linux.it.net.cn 作者:IT

在大二的Linux课程设计上基于CentOS7做过MySQL主从备份,在CentOS7上已经使用mariadb代替了MySQL。因此使用yum install mysql实际上安装的是mariadb. 
最近做测试需要安装MySQL,本着快速的原则使用了rpm 
系统是CentOS7-1604-mini最小化安装版 
1.安装依赖以及删除mariadb的lib库默认是自带的

yum install -y wget libaio
yum remove  mariadb*

2.下载MySQL RPM包

cd /tmp/ && wget -c http://downloads.mysql.com/archives/get/file/MySQL-5.6.28-1.linux_glibc2.5.x86_64.rpm-bundle.tar

3.解压tar包

cd /tmp/ && tar -xvf MySQL-5.6.28-1.linux_glibc2.5.x86_64.rpm-bundle.tar 
rm -rf /tmp/MySQL-5.6.28-1.linux_glibc2.5.x86_64.rpm-bundle.tar

4.安装相关的软件

cd /tmp/ && rpm -ivh MySQL*

5.启动

systemctl enable mysql #开机自启动
systemctl start mysql  #启动mysql

6.修改密码mysql在安装的时候,为了安全默认会生成随机密码位置在 /root/.mysql_secret  如下面的文件

[root@izltf35j605nncz user]# cat /root/.mysql_secret
# The random password set for the root user at Sat Feb 25 14:50:11 2017 (local time): TjMBpQi0UeNWjUev

7.修改密码  修改密码有几种方式  首先查看原有的配置  mysql> select host,user,password from mysql.user;

host user password
localhost root *4F5D16242740A35AC75396074A16FCA85E733DDE
izltf35j605nncz root *4F5D16242740A35AC75396074A16FCA85E733DDE
127.0.0.1 root *4F5D16242740A35AC75396074A16FCA85E733DDE
% sakila *94099046963A7BE31E0443DC095E0657EB47EA94
% test *A1774F61D244D786BB7AF496A710B809508AE6B2
% root *A1774F61D244D786BB7AF496A710B809508AE6B2

6 rows in set (0.00 sec)

1.使用set password for ‘用户名’@’主机名’=password(‘密码’);

set password for 'root'@'localhost'=password('123456')

mysql> select host,user,password from mysql.user;

host user password
localhost root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
izltf35j605nncz root *4F5D16242740A35AC75396074A16FCA85E733DDE
127.0.0.1 root *4F5D16242740A35AC75396074A16FCA85E733DDE
% sakila *94099046963A7BE31E0443DC095E0657EB47EA94
% test *A1774F61D244D786BB7AF496A710B809508AE6B2
% root *A1774F61D244D786BB7AF496A710B809508AE6B2

6 rows in set (0.00 sec)

2.使用update修改 update mysql.user set password=password(‘123456’) where user=’root’;

update mysql.user set password=password('123456') where user='root';

mysql> select host,user,password from mysql.user;

host user password
localhost root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
izltf35j605nncz root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
127.0.0.1 root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
% sakila *94099046963A7BE31E0443DC095E0657EB47EA94
% test *A1774F61D244D786BB7AF496A710B809508AE6B2
% root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

6 rows in set (0.00 sec)

3.使用grant all privileges on sakila.* to ‘sakila’@’%’ identified by ‘123456’;修改.设置远程访问

grant all privileges on sakila.* to 'sakila'@'%' identified by '123456';

mysql> select host,user,password from mysql.user;

host user password
localhost root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
izltf35j605nncz root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
127.0.0.1 root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
% sakila *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
% test *A1774F61D244D786BB7AF496A710B809508AE6B2
% root *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

6 rows in set (0.00 sec)

注意:初次安装设置密码时候一定要使用update修改密码,更改root密码。这样使用localhost或者127.0.0.1时候密码都一样。否则很有可能不一样,导致不能使用,如果数据库服务器和web等在一个服务器的时候,尽量使用localhost。在linux下mysql使用localhost的时候使用的是unix套接字,而其他使用的是tcp/ip协议。




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容