以前安装Mysql都是要自己去网上选择一个特定版本,然后再下载到服务器安装,而且不同版本的相关命令也有所不同,学习记忆成本也非常高。现在官网可以通过安装yum的依赖库自由选择安装,非常的方便,今天来分享下。
- Adding the MySQL Yum Repository
sudo rpm -Uvh mysql57-community-release-el6-n.noarch.rpm
- Selecting a Release Series
yum repolist all | grep mysql
通过这个命令可以看到不同版本的默认启用情况,然后我们可以选择自己的需要的版本,如果需要变更,需要修改/etc/yum.repos.d/mysql-community.repo的文件。
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
例如需要启动Mysql5.6,则将5.7的enabled=0,将5.6的enabled=1即可。修改完后确认最终版本:
yum repolist enabled | grep mysql
- Installing MySQL
sudo yum install mysql-community-server
- Starting the MySQL Server
Start the MySQL server with the following command:
shell> sudo service mysqld start
For EL7-based platforms, this is the preferred command:
shell> sudo systemctl start mysqld.service
You can check the status of the MySQL server with the following command:
shell> sudo service mysqld status
For EL7-based platforms, this is the preferred command:
shell> sudo systemctl status mysqld.service
查看启动后的初始密码:
sudo grep 'temporary password' /var/log/mysqld.log
最后通过初试密码登录并且修改root的密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
大家喜欢可以访问我的个人网站:http://www.yingminxing.com
如有疑问,欢迎沟通交流:QQ:370399195, 微信:yingminxing1988