安装 MySQL 数据库
Step 00
如果你安装了旧版本的 MySQL 如:5.6/7,那么要先移除 5.6/7 的内容,数据怎么迁移,没研究;只谈删除。
为什么要删除?因为本文要安装的是 8.0 版本,如果没有移除在安装 8.0 的时候会提示 5.6/7 与 8.0 会冲突,无法进行安装。
查看已经安装的 MySQL
[root@~]# yum list installed | grep "mysql"
mysql-community-client.x86_64 5.7.17-1.el7 @mysql57-community
mysql-community-common.x86_64 5.7.17-1.el7 @mysql80-community
mysql-community-libs.x86_64 5.7.17-1.el7 @mysql57-community
mysql-community-server.x86_64 5.7.17-1.el7 @mysql57-community
mysql80-community-release.noarch el7-9 installed
使用 yum 进行移除即可
[root@~]# yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-server
[root@~]# rm -rf /var/lib/mysql
[root@~]# rm /etc/my.cnf
查看 rpm 安装的包
// rpm -qa | grep -i mysql 效果一样
[root@~]# rpm -qa | grep "mysql"
mysql-community-client-5.7.17-1.el7.x86_64
mysql-community-libs-5.7.17-1.el7.x86_64
mysql-community-common-5.7.17-1.el7.x86_64
mysql57-community-release-el7-9.noarch
mysql-community-server-5.7.17-1.el7.x86_64
使用 rpm 进行移除
[root@~]# rpm -e mysql-community-client-5.7.17-1.el7.x86_64
[root@~]# rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
[root@~]# rpm -e mysql-community-common-5.7.17-1.el7.x86_64
[root@~]# rpm -e mysql57-community-release-el7-9.noarch
[root@~]# rpm -e mysql-community-server-5.7.17-1.el7.x86_64
删除配置文件
[root@~]# rm –rf /usr/my.cnf
[root@~]# rm -rf /root/.mysql_sercret
删除服务
[root@~]# systemctl list-unit-files | grep "mysql"
mysqld.service enabled
[root@~]# chkconfig --del mysqld
删除分散的文件
[root@~]# whereis mysql
mysql: /usr/share/mysql
[root@~]# rm -rf /usr/share/mysql
[root@~]# rm -rf /var/log/mysqld.log
[root@~]# rm-rf /var/run/mysql/
Step 01
先去 MySQL 的官网 : https://dev.mysql.com
找到 yum 的安装源
mysql yum向下滚动网页,复制要下载的文件名
mysql从 repo 里面找到它
mysql 确认回到 Xsell 6 里面,使用 wget 下载到本地
[root@~]# wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
mysql80-community-release-el7-1.noarch.rpm
写入 yum localinstall 里面
[root@~]# sudo yum localinstall mysql80-community-release-el7-1.noarch.rpm
查看是否成功写入,如果有 mysql 的库就成功了
[root@~]# ls /etc/yum.repos.d | grep "mysql"
mysql-community.repo
mysql-community-source.repo
查看开启的 mysql 安装源
[root@~]# yum repolist enabled | grep "mysql.*-community.*"
!mysql-connectors-community/x86_64 MySQL Connectors Community 65
!mysql-tools-community/x86_64 MySQL Tools Community 69
!mysql80-community/x86_64 MySQL 8.0 Community Server 33
开始进行安装,文件很大 [1.7 G],慢慢等吧,如果最后出现 Complete! 就成功了
[root@~]# sudo yum install mysql-community-server
启动服务
[root@~]# systemctl start mysqld.service
如果出现了错误,第一次启动都是这样的......
[root@~]# systemctl start mysqld.service
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
按照上面提示的两个命令进行操作,你会发现什么有用的信息都没有。
所以我们要打开日志信息
[root@~]# cat /var/log/mysqld.log
你会看到其中有两条 ERROR 信息
[ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
[ERROR] Can't start server: can't create PID file: No such file or directory
创建文件
[root@~]# mkdir -p /var/run/mysqld/
重新启动,恭喜你喜提新坑,这次是权限问题
[ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
ERROR] Can't start server: can't create PID file: Permission denied
这里的原因是因为文件夹是由 root 创建的,权限是 root ,mysql 如果要操作就要拥有权限
[root@~]# ls -la /var/run/ | grep "mysqld"
drwxr-xr-x 2 root root 40 Sep 6 12:46 mysqld
// 改成 mysql
[root@~]# chown mysql.mysql /var/run/mysqld/
[root@~]# ls -la /var/run/ | grep "mysqld"
drwxr-xr-x 2 mysql mysql 40 Sep 6 12:48 mysqld
重新启动服务
[root@~]# service restart mysqld.service
[root@~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-09-05 18:51:50 CST; 17h ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 9911 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 9933 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─9933 /usr/sbin/mysqld
Sep 05 18:51:48 izwz9dnfbgdn5tleje5eitz systemd[1]: Starting MySQL Server...
Sep 05 18:51:50 izwz9dnfbgdn5tleje5eitz systemd[1]: Started MySQL Server.
看到 Active: active (running) 就表明成功了。
进入 mysql 页面,先找临时密码
[root@~]# grep 'temporary password' /var/log/mysqld.log
2018-09-05T10:03:00.388929Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 2rlYx79fo;pU
2rlYx79fo;pU
它就是密码。
使用这个密码登录 mysql
[root@~]# mysql -uroot -p
Enter password: // 复制粘贴就行了
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.12
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
输入一个指令尝试一下,如果看到这个信息,证明密码过期了
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
需要重新设置密码才能访问:
......
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '**1my/';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
上面你如果密码过于简单,那么就会出错
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
按要求重新设置
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '**1My/';
Query OK, 0 rows affected (0.09 sec)
设置密码永不过期
......
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.06 sec)
exit 退出 mysql
......
mysql> exit
Bye
文档的内容,认真看看吧!
大功告成!
网友评论