1.解压安装包
mysql下载:
https://www.mysql.com/cn/
https://dev.mysql.com/downloads/mysql/
选择社区版,选择版本下载
# tar xvJf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql8
2.授权与运行
[root@localhost ~]# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql8
[root@localhost ~]# cd /usr/local/mysql8/
[root@localhost mysql8]# mkdir data
[root@localhost mysql8]# groupadd mysql
[root@localhost mysql8]# useradd -g mysql mysql
[root@localhost mysql8]# chown -R mysql.mysql /usr/local/mysql8
[root@localhost mysql8]# cd bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data --lower-case-table-names=1
显示的最后是密码
先删除原本的my.cnf,再编辑my.cnf文件 (注释mysqld_safe)
3.编辑文件
# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql8/
datadir=/usr/local/mysql8/data/
lower-case-table-names=1 #定义mysql数据库不区分大小写
#log-bin=mysql-bin #开启binlog日志
#binlog-format=ROW #选择模式
#binlog_expire_logs_seconds=172800 #定义binlog日志的保存时间为2天
4.开机自启动
[root@localhost mysql8]# cp -a /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql8]# chmod +x /etc/init.d/mysqld
[root@localhost mysql8]# chkconfig --add mysqld
[root@localhost mysql8]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@localhost mysql8]# systemctl status mysql.service
将mysql命令添加到服务
[root@localhost mysql8]# ln -s /usr/local/mysql8/bin/mysql /usr/bin
5.修改root密码和登录方式
# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Weige@309';
mysql> flush privileges;
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> flush privileges;