1. 下载:
官网下载: MySQL :: Download MySQL Community Server
2. 解压
将下载好的tar文件放到centos中,目录文件夹名称自定义,解压后得到:
[root@localhost mysql]# tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar mysql-community-client-8.0.26-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm mysql-community-common-8.0.26-1.el7.x86_64.rpm mysql-community-devel-8.0.26-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm mysql-community-libs-8.0.26-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm mysql-community-server-8.0.26-1.el7.x86_64.rpm mysql-community-test-8.0.26-1.el7.x86_64.rpm
这里我们只需要client和server,其他不需要安装
将centos7会自带的mariadb删除
rpm -e --nodeps mariadb-libs
3. 安装
按照以下顺序执行
rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm --force --nodeps
这里需要注意的是,如果不加 --force --nodeps 可能会报错,这是由于yum安装了旧版本的GPG keys造成的。
依赖检测失败: mariadb-libs 被 mysql-community-libs-8.0.23-1.el7.x86_64 取代...
安装完后默认目录为:/var/lib/mysql ,需要设置权限
chmod -R 777 /var/lib/mysql
初始化mysql
mysqld --initialize
获取默认密码
cat /var/log/mysqld.log
[root@localhost lib]# cat /var/log/mysqld.log 2022-12-03T17:30:00.122696Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 6579 2022-12-03T17:30:00.265192Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-12-03T17:30:03.100689Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-12-03T17:30:08.936428Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main 2022-12-03T17:30:08.947078Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main 2022-12-03T17:30:09.044202Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: BrFwhHdcN0)p
日志最后的 BrFwhHdcN0)p 为默认密码。
如果没启动mysql服务,则启动一下
[root@localhost lib]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@localhost lib]# service mysqld status Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 日 2022-12-04 01:40:35 CST; 17s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 18920 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 19362 (mysqld) Status: "Server is operational" Tasks: 38 CGroup: /system.slice/mysqld.service └─19362 /usr/sbin/mysqld 12月 04 01:40:16 localhost.localdomain systemd[1]: Starting MySQL Server... 12月 04 01:40:35 localhost.localdomain systemd[1]: Started MySQL Server.
重新设置密码:
进入msql命令编辑器, 密码为刚才日志里的密码:BrFwhHdcN0)p
[root@localhost lib]# mysql -uroot -p Enter password:
这里需要注意:新的密码一定要符合mysql8的规范,不然更新不了,或者是更新了后面有问题!
mysql> alter user 'root'@'localhost' identified by 'Mhf1997=qfl'; Query OK, 0 rows affected (0.10 sec)
设置Navicat远程连接:
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql>
修改 root 的 host 为 %
mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0
执行俩次:GRANT ALL ON *.* TO 'root'@'%';
mysql> GRANT ALL ON *.* TO 'root'@'%'; ERROR 1410 (42000): You are not allowed to create a user with GRANT mysql> GRANT ALL ON *.* TO 'root'@'%'; Query OK, 0 rows affected (0.03 sec)
设置一下立即生效:
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.03 sec)
重启mysql服务
service mysqld restart
这样就可以使用navicat远程连接了!
补充知识:
linux操作mysql基本命令
service mysqld status #查看mysql状态 service mysqld stop #关闭 service mysqld start #启动 service mysqld restart #重启
使用rpm安装mysql的默认目录:
数据库目录 /var/lib/mysql/
配置文件 /usr/share/mysql(mysql.server命令及配置文件)
相关命令 /usr/bin(mysqladmin mysqldump等命令)
启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录)