new
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
# CentOS8 安装 MySQL8.0(RPM)
|
||||
|
||||
[作者博客](https://blog.51cto.com/u_11261718) [原文地址](https://blog.51cto.com/u_11261718/2465227)
|
||||
|
||||
> 环境:Linux centos8 4.18.0-80.el8.x86_64、Mysql8.0.18
|
||||
|
||||
## 1、Mysql官网下载RPM包
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 2、检查是否安装过
|
||||
|
||||
```html
|
||||
rpm -qa | grep -i mysql
|
||||
```
|
||||
|
||||
## 3、卸载之前的安装
|
||||
|
||||
```html
|
||||
rpm -e --nodeps 软件名 //强力删除,对相关依赖的文件也进行强力删除
|
||||
```
|
||||
|
||||
## 4、安装客户端(mysql-client)
|
||||
|
||||
```html
|
||||
rpm -ivh rpm包
|
||||
* 安装mysql-community-common-8.0.18
|
||||
* 安装mysql-community-libs-8.0.18
|
||||
* 安装mysql-community-client-8.0.18(前两个是其依赖)
|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 5、安装服务端(mysql-server)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 6、查看是否安装成功
|
||||
|
||||
```html
|
||||
有以下方式查看:
|
||||
* ps -ef | grep mysql
|
||||
* cat /etc/group | grep mysql
|
||||
* cat /etc/password | grep mysql
|
||||
* mysqladmin --version
|
||||
...
|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 7、初始化mysql
|
||||
|
||||
```html
|
||||
mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码
|
||||
```
|
||||
|
||||
## 8、启动mysql服务
|
||||
|
||||
```html
|
||||
systemctl start mysqld
|
||||
```
|
||||
|
||||

|
||||
|
||||
```html
|
||||
启动失败,因为/var/lib/mysql目录权限不够
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 9、/var/lib/mysql目录权限授权
|
||||
|
||||
```html
|
||||
chown -R mysql:mysql /var/lib/mysql/
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 10、启动mysql服务
|
||||
|
||||
```html
|
||||
systemctl start mysqld //启动
|
||||
ps -ef | grep mysql //查看mysql服务
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 11、查看初始化随机生成的root密码
|
||||
|
||||
```html
|
||||
cat /var/log/mysqld.log | grep password
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 12、安全设置
|
||||
|
||||
```html
|
||||
mysql_secure_installation
|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 13、mysql登录
|
||||
|
||||
```html
|
||||
mysql -uroot -p //随机密码登录
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 14、重置密码(Mysql8.0+有变化)
|
||||
|
||||
```html
|
||||
先把root的旧密码置空
|
||||
use mysql;
|
||||
update user set authentication_string='' where user='root';
|
||||
备注:Mysql5.7+ password字段 已改成 authentication_string字段
|
||||
```
|
||||
|
||||

|
||||
|
||||
```html
|
||||
重置成新密码
|
||||
alter user 'root'@'localhost' identified by 'newpassword';
|
||||
备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意)
|
||||
Mysql8.0之前:
|
||||
update user set password=password('root') where user='root';
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 15、退出后使用新密码再登录mysql
|
||||
|
||||
```html
|
||||
mysql -uroot -proot
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 16、如何停止、重启和查看mysql服务
|
||||
|
||||
```html
|
||||
systemctl stop mysqld //停止服务
|
||||
systemctl restart mysqld //重启服务
|
||||
systemctl status mysqld //查看服务
|
||||
```
|
||||
|
||||
## 17、mysql的相关安装目录文件
|
||||
|
||||
```html
|
||||
/usr/bin //相关命令
|
||||
```
|
||||
|
||||

|
||||
|
||||
```html
|
||||
/usr/share/mysql //配置文件目录
|
||||
```
|
||||
|
||||

|
||||
|
||||
```html
|
||||
/var/lib/mysql //数据库文件存放目录
|
||||
```
|
||||
|
||||

|
||||
|
||||
```html
|
||||
/etc/my.cnf //mysql的启动配置文件
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 18、后记
|
||||
|
||||
```html
|
||||
my.ini //windows操作系统下的配置文件
|
||||
my.cnf //linux操作系统下的配置文件
|
||||
mysqld //是后台守护进程,即mysql daemon
|
||||
mysql //是客户端命令行
|
||||
```
|
||||
Reference in New Issue
Block a user