美文网首页工作生活
安装mysql(centeros7版)

安装mysql(centeros7版)

作者: 云雾之外 | 来源:发表于2019-07-03 23:38 被阅读0次
  1. 检查是否安装已安装
yum list installed | grep mysql   
  1. 卸载已安装
yum -y remove mysql-libs.x86_64    
  1. 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

4.安装mysql源

yum localinstall mysql57-community-release-el7-8.noarch.rpm
[root@izj6chsagigq6n2yuytoolz /]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution
  1. 验证源安装是否成功
yum repolist enabled | grep "mysql.*-community.*"
[root@izj6chsagigq6n2yuytoolz /]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                 108
mysql-tools-community/x86_64      MySQL Tools Community                      90
mysql57-community/x86_64          MySQL 5.7 Community Server                 347

6.设置默认需要安装的mysql版本

vim /etc/yum.repos.d/mysql-community.repo

打开后如下,想要安装特定版本enabled=1,其他enabled=0即可,会显示5.5. 5.6. 5.7三个版本,默认是5.7版本。

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  1. 安装mysql
yum install mysql-community-server 
  1. 启动 mysql
systemctl start mysqld

对应的停止命令如下

systemctl stop mysqld

查看状态

systemctl status mysqld

9.设置开机启动

systemctl enable mysqld
systemctl daemon-reload
  1. 查看默认密码(mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码,
    有时候生成的密码是特殊字符,比如生成的密码 sX;qQZ.L;6Ml 那就用转义 sX;qQZ.L;6Ml 即可)
grep 'temporary password' /var/log/mysqld.log

从下方结果可以看出密码是 f9)LfGvq,3da

# 2019-07-03T12:06:09.610118Z 1 [Note] A temporary password is generated for root@localhost: f9)LfGvq,3da
  1. 登录mysql(-u账号 -p密码)
mysql -uroot -p9)LfGvq,3da

结果报错如下

# mysql: [Warning] Using a password on the command line interface can be insecure.
#ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

该报错说明,当前用户没有权限,原因是需要重置密码才能使用
(阿里云服务器的为了安全的特别要求,vultr云服务器并没有此要求)

  1. 修改密码
  • 通过ssh命令连接Linux云服务器来进行修改MYSQL密码(ssh root@IP)
ssh root@47.240.8.233
  • 登录mysql
mysql -u root -p -p9)LfGvq,3da
  • 修改密码
alter user user() identified by "123456";
  • 密码太简单会报如下错误,看到如下错误请输入足够复杂的密码,比如@qq123456
Your password does not satisfy the current policy requirements

至此,mysql安装成功。

相关文章

网友评论

    本文标题:安装mysql(centeros7版)

    本文链接:https://www.haomeiwen.com/subject/jebhhctx.html