centos7 安装 mysql8 【亲测两次】

//
某位大佬说过,mysql只有5.5、5.7、8.0三个版本,所以当然我们要装最新版咯
还有就是centos7是比较稳定的版本,很多云服务器都是7为默认版本

// 网上很多mysql8的安装都有问题,害得我装了删、删了装,但也总结出了一套完美流程
如果你是第一次在linux上装mysql8,强烈推荐

1. 版本问题

centos7对应的是mysql8.0中后缀是el7的版本,centos8则是el9,不要安装错

2. 历史遗留问题

有些云服务器会自带margindb或者有mysql,在装之前要全部删除
通过yum list installed | grep mysql命令查找是否装过应用

3. 下载并安装

首先在/usr/local下创建mysql文件夹
接着使用 wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm下载rpm包
然后下载 rpm -ivh mysql80-community-release-el7-1.noarch.rpm
查看是否下载成功 yum list installed | grep mysql
下载成功后安装 yum install mysql-community-server。这里会有两次输入y的情况,系统会自动下载依赖

4. 运行mysql

当看到complete说明安装成功了

[root@centos01 mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@centos01 mysql]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit not found.
[root@centos01 mysql]# service mysqlid status
Redirecting to /bin/systemctl status mysqlid.service
Unit mysqlid.service could not be found.
[root@centos01 mysql]# mysql -version
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[centos01@centos01 ~]$ mysql
ERROR 1045 (28000): Access denied for user 'centos01'@'localhost' (using password: NO)
[centos01@centos01 ~]$ service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[centos01@centos01 ~]$ service mysqld status
Redirecting to /bin/systemctl status mysqld.service

在最后看到绿色的running说明启动成功

设置mysql

通过 grep ‘temporary password’ /var/log/mysqld.log查看初始密码
然后使用 mysql -u root -p输入密码
进去以后改新密码 alter user ‘root’@‘localhost’ identified by ‘sds132_dsd’;
新密码要满足有字母数字符号。嫌麻烦可以在设置完密码后将mysql的密码策略设为LOW,这样就可以设置123456这样的密码了

尾声

设置好就可以使用了,
如果wget无法用的,就yum下载wget
如果初始密码字母l和数字1分不清的,就直接在-p后跟密码,这样密码可以复制粘贴,就不会错。-p和密码中间没有空格
如果设置密码后无效的,就flush一下
如果报拒绝xxx访问数据库的,就将数据库mysql表中root字段的允许字段设为%
如果设置完后还是报错的,那就flush hosts
如果按我的步骤,出了上面以外的错误,就重启mysql
如果重启也没用,那就把mysql删干净,重新安装一遍

你可能感兴趣的:(数据库)