版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43126117/article/details/100840495
检查Linux服务器是否有Mysql
[root@VM_0_16_centos ~]# rpm -qa|grep mysql* [root@VM_0_16_centos ~]# rpm -qa|grep -i mysql
如有,必须卸载干净,否则后面安装会报各种错误。
我们还是通过华为云镜像进行下载 MySql-Server、MySql-Client这两个服务,其他(开发库、兼容库、测试组件等)不安装。
创建目录,进入目录,并下载文件。
[root@VM_0_16_centos ~]# mkdir /usr/lib/mysql [root@VM_0_16_centos ~]# cd /usr/lib/mysql [root@VM_0_16_centos mysql]# wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-server-8.0.16-2.el7.x86_64.rpm [root@VM_0_16_centos mysql]# wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-client-8.0.16-2.el7.x86_64.rpm
我安装的时候提示我需要两个服务,我就下载安装了。
[root@VM_0_16_centos mysql]# wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-common-8.0.16-2.el7.x86_64.rpm [root@VM_0_16_centos mysql]# wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-libs-8.0.16-2.el7.x86_64.rpm
安装顺序如下:common>libs>server>client
注意的一点是,从 RPM 版本 4.1 开始,在安装或升级软件包时会检查软件包的签名。如果签名校验失败,你就会看到如下所示 的错误消息:
Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
安装的时候需要取消校验签名 --force --nodeps
--force 强行置换套件或文件。
--nodeps 不验证套件档的相互关联性。
[root@VM_0_16_centos mysql]# rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm [root@VM_0_16_centos mysql]# rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm --force --nodeps [root@VM_0_16_centos mysql]# rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm --force --nodeps [root@VM_0_16_centos mysql]# rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm
安装完毕后,启动mysql服务
[root@VM_0_16_centos ~]# systemctl start mysqld
我启动的时候,报了很多错误。
所以给一个通用的解法:检查mysql服务的系统日志,看看报什么错。路径是什么呢? 可以通过配置文件获取
[root@VM_0_16_centos ~]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic- s is recommended to prevent assorted security risks symbolic- s=0 log-error=/var/log/mysqld.log //日志路径 pid-file=/var/run/mysqld/mysqld.pid datadir=/opt/data skip-grant-tables
然后登陆MySQL,并修改密码
通过 grep "password" /var/log/mysqld.log ,取得mysql初始化随机密码,但是我这里不可以。
只能通过修改配置文件,进入无保护状态下的MySQL。
[root@VM_0_16_centos ~]# vi /etc/my.cnf
//加上
skip-grant-tables
//重启
[root@VM_0_16_centos ~]# systemctl restart mysqld
//无密码进入
[root@VM_0_16_centos ~]# mysql -uroot -p
use mysql;
UPDATE user SET authentication_string = Password ('密码') WHERE User = 'root' ;
flush privileges ;
quit;
//删除/etc/my.cnf 中 skip-grant-tables
//重启再次通过刚刚设置的密码进入系统,可能还要重新设置密码,刚刚设置的好像只是临时的
SET PASSWORD = PASSWORD('!Qw56:'); //密码需要很复杂,否则报错
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
//设置密码为永久
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
//设置外部可以访问
grant all privileges on *.* to root@"%" identified by "!Qw56:";
//更新
flush privileges; 还需要开放云服务器安全组的端口。
继续阅读与本文标签相同的文章
-
业务复杂=if else?刚来的大神竟然用策略+工厂彻底干掉了他们!
2026-05-16栏目: 教程
-
ElasticSearch(7.2.2)-es的范围查询
2026-05-16栏目: 教程
-
Selenium编写自动化用例的8种技巧
2026-05-16栏目: 教程
-
MongoDB实现问卷/考试设计
2026-05-16栏目: 教程
-
JVM虚拟机面试大全
2026-05-16栏目: 教程
