CentOS6、7安装MySQL5.7全教程
CentOS6、7安装MySQL5.7全教程
做开发总得用到数据吧,Linux作为服务器,总得有一个数据库来存储测试用的数据,所以呢,这里附上CentOS6、7安装MySQL5.7的教程喔~
用到的工具:CentOs6、7;Mysql依赖包
Step1. 查看已安装的mysql:
# yum list installed | grep mysql mysql-libs.x86_64 5.1.71-1.el6 @anaconda-CentOS-201311272149.x86_64/6.5
卸载当前mysql:
# yum -y remove mysql-libs.x86_64
Step2. 下载安装所需依赖:
先到https://dev.mysql.com/downloads/repo/yum/下载,根据自己Linux版本来选择,比如本人是Centos6.5,故选择第二个,依次类推:
将下载的mysql80-community-release-el6-1.noarch.rpm文件上传到Linux服务器中
Step3. 安装依赖:
使用以下命令,注意此命令需要在mysql80-community-release-el6-1.noarch.rpm文件的所在目录下执行。
执行过程中会出现Is this ok [y/N]: ,输入y就行了。
# yum localinstall mysql80-community-release-el6-1.noarch.rpm
执行完之后,使用# ls /etc/yum.repos.d命令可以看到多出来了两个文件
# ls /etc/yum.repos.d mysql-community.repo mysql-community-source.repo
Step4. 运行yum repolist enabled | grep mysql查看mysql57是否可用。
如果运行的结果如下:
# yum repolist enabled | grep mysql mysql-connectors-community MySQL Connectors Community 59 mysql-tools-community MySQL Tools Community 65 mysql80-community MySQL 8.0 Community Server 29
则需要使用命令vim /etc/yum.repos.d/mysql-community.repo修改mysql57的enabled为1,而其他的版本则设为0.具体如下:
vim /etc/yum.repos.d/mysql-community.repo
修改部分:
...... # Enable to use MySQL 5.7 [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql ...... [mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
设置完的运行结果为:
# yum repolist enabled | grep mysql mysql-connectors-community MySQL Connectors Community 59 mysql-tools-community MySQL Tools Community 65 mysql57-community MySQL 5.7 Community Server 273
Step5. 开始安装:
# yum install mysql-community-server
如果中途出错停止,一般是因为网速原因,可以重复执行此命令
Step6. 安装完成后,启动mysql服务(可能第一次会出错,那就再运行一次~):
# service mysqld start
Initializing MySQL database: [FAILED]
# service mysqld start
Starting mysqld: [ OK ]
Step7. 查看默认root用户的密码:
# cat /var/log/mysqld.log | grep root@localhost 2018-08-29T03:11:26.560863Z 1 [Note] A temporary password is generated for root@localhost: DJ#erA*-p6&?
DJ#erA*-p6&? 即为root用户的初始密码
Step8. 使用mysql -uroot -p命令登录,需要输入上一步中的密码。
进入之后进行任何操作都会提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.这时需要重置密码:
mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> set password=password('new_password'); Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> alter user 'root'@'localhost' password expire never; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
再退出mysql,使用新密码重新登陆即可。
咋样,是不是hin简单哩,有何问题请留下你的评论喔~