1. 检测是否自带Mysql

rpm -qa | grep mysql

2. 若已安装,可卸载

rpm -e mysql-libs.x86_64??(已安装的包名)  // 普通删除模式
rpm -e --nodeps mysql-libs.x86_64??  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

3. 下载mysql57

yum install wget
wget https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm  # *上两句有点问题,用这个* #

4. # *3*若成功,这步忽略# 使用rpm安装 

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

5. 安装mysql-community-server

yum -y install mysql-community-server

6. 初始化 MySQL、开机启动设置

mysqld --initialize

 

systemctl enable mysqld
systemctl daemon-reload

 

7. 启动mysql服务

 

 

service mysqld start

8. 此时出现报错

 

 

Redirecting to /bin/systemctl start  mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

查看mysql服务的启动日志

 

 

tail -f /var/log/mysqld.log

遇到一大堆问题

 

1)查看/var/run/mysqld/的属主和属组是root,mysql并不能在其中创建文件,后修改该目录的属主和属组

 

chown mysql.mysql /var/run/mysqld/

2)ibdata1等文件不能被写入,进入mysql安装目录,修改文件权限

 

chmod 777 /var/lib/mysql/ibdata1

3)Failed to create file(file: './auto.cnf', errno 13),修改整个目录的权限

 

 

chmod -R 777 /var/lib/mysql/

以下未部分报错信息,做了很多操作无效,改了权限后不报错(暂时无视)

 

 

[ERROR] InnoDB: Cannot open datafile for read-only: './sys/sys_config.ibd' OS error: 81

[ERROR] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.

9. 重启sql

 

 

service mysqld restart

10. 查看 MySQL 运行状态

 

 

service mysqld status
或systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-09-15 23:49:41 CST; 21min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 32312 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 32294 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 32316 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─32316 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
 
Sep 15 23:49:41 iZbp1iir8v4wm901e3gmz0Z systemd[1]: mysqld.service holdoff time over, s....
Sep 15 23:49:41 iZbp1iir8v4wm901e3gmz0Z systemd[1]: Starting MySQL Server...
Sep 15 23:49:41 iZbp1iir8v4wm901e3gmz0Z systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.

11. 验证mysql安装

 

 

 

[root@iZbp1iir8v4wm901e3gmz0Z init.d]# mysqladmin --version
mysqladmin  Ver 8.42 Distrib 5.7.23, for Linux on x86_64

12. 创建用户名密码,只记用到的指令吧,一个个来....

 

1)因为修改时候报错,所以先修改配置文件vim /etc/my.cnf,文件末尾一行加上skip-grant-tables不需要密码登录,保存后重启mysql,执行service mysqld restart

20180916014821.png

2)用root账号进入mysql,指令:mysql -uroot -p,进入mysql界面,输入use mysql,使用select user,host from user; 查看是否有用户名为空的localhost用户,若有则删除:Delete FROM user Where User='' and Host='localhost';(我把除root以外的用户都删了),执行成功后刷新MySQL的系统权限相关表,以防止更改后拒绝访问,执行flush privileges;20180916020539.png

3)修改root的密码:在mysql中输入指令update user set authentication_string=password('Jxxjxx68024787') where user='root'20180916021045.png

4)将配置vim /etc/my.cnf中的不需要密码登录那一行注销,并重启mysql:service mysqld restart

5)此时进入mysql又出妖蛾子,输入啥都提示改密码,那特么只能改了啊,输入:alter user user() identified by "新密码";

问题参考:https://blog.csdn.net/muziljx/article/details/81541896

这里在想,既然又让改密码,是不是3)修改root的密码这一步可以省略?

20180916021752.png

6)由于上面这个报错,在配置vim /etc/my.cnf中加入一行,设置密码永不过期:default_password_lifetime=0

注意:若修改过mysql的用户名密码,wordpress配置需要修改相关内容,vim /var/www/html/wp-config.php

nginx下修改vim /usr/share/nginx/html/wp-config.php

13. 开启远程访问

修改配置文件vim /etc/my.cnf,新增一行(若已存在则修改地址)bind-address = 0.0.0.0

20180916024037.png

14. 新增用户,进入mysql中输入指令GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;(user处填用户名,%表示所有的电脑都可以连接,也可以设置某个ip地址运行连接,password处填密码)。

20180916020755.png

 

posted on 2021-08-07 22:51  讲道理好嘛  阅读(1187)  评论(0编辑  收藏  举报