1、解压MySQL
[root@k8s-master1 ~]# tar -zxvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.gz
mysql-8.0.17-linux-glibc2.12-x86_64/
mysql-8.0.17-linux-glibc2.12-x86_64/bin/
mysql-8.0.17-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.17-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.17-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.17-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.17-linux-glibc2.12-x86_64/bin/mysql
mysql-8.0.17-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-8.0.17-linux-glibc2.12-x86_64/bin/mysql_secure_installation
mysql-8.0.17-linux-glibc2.12-x86_64/bin/mysql_ssl_rsa_setup
[root@k8s-master1 ~]# mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql
2、创建目录和授权
[root@k8s-master1 ~]# mkdir -p /data/mysql/mysql
[root@k8s-master1 ~]# mkdir -p /data/mysql/logs
[root@k8s-master1 ~]# useradd mysql
[root@k8s-master1 ~]# chown -R mysql:mysql /usr/local/mysql/
[root@k8s-master1 ~]# chown -R mysql:mysql /data/mysql/
3、修改配置文件
[root@k8s-master1 ~]# cp /etc/my.cnf /etc/my.cnf.bak2021
[root@k8s-master1 ~]# vim /etc/my.cnf
注意:server_id=100 不同
4、初始化:错误了解决方法
[root@k8s-master1 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/
删除原来的目录
[root@k8s-master1 mysql]# ll
总用量 0
drwxr-xr-x 2 mysql mysql 29 1月 4 16:18 logs
drwxr-xr-x 2 mysql mysql 6 1月 4 16:19 mysql
[root@k8s-master1 mysql]# rm -rf *
[root@k8s-master1 mysql]# mkdir logs
[root@k8s-master1 mysql]# mkdir mysql
5、重新授权
[root@k8s-master1 mysql]# chown -R mysql:mysql /data/mysql/
[root@k8s-master1 mysql]# chown -R mysql:mysql /usr/local/mysql/
再次初始化
[root@k8s-master1 mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql/
6、配置启动文件路径
[root@k8s-master1 ~]# vim /usr/local/mysql/support-files/mysql.server
[root@k8s-master1 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@k8s-master1 mysql]# chmod 775 /etc/init.d/mysqld
[root@k8s-master1 mysql]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@k8s-master1 mysql]# source /etc/profile
7、启动mysql
[root@k8s-master1 mysql]# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!
8、登录mysql并查找初始密码
9、修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> user mysql
mysql> select user,host from mysql.user;
相关阅读:
1、阿里云--MySQL 备份
2、MySQL工作常用命令
3、干货--MySQL工作常用Select命令
4、Mysql二进制日志binlog命令
请 扫 码 关 注