[Linux系统安装Mysql8.4;CentOS7下安装Mysql8.4]

一、检查

先检查有没有安装过mysql 或者 mariabd

1 rpm -qa | grep -i mysql
2 rpm -qa | grep -i mariabd

如有,批量化删除安装包

1 rpm -qa | grep mysql  | xargs  yum -y remove

rpm -qa | grep mariadb
#mariadb-libs-5.5.68-1.el7.x86_64
rpm -e --nodeps mariadb-libs

检查是否有 配置文件

ls /etc/my.cnf

如果有,删除

rm -rf /etc/my.cnf

which mysql  #检查 是否有客户端 
which mysqld  #检查 是否有服务端

二、安装

# 解压
tar -xvf #包名   

安装顺序

#common
rpm -ivh mysql-community-common-8.4.5-1.el8.aarch64.rpm 

#client-plugins
rpm -ivh mysql-community-client-plugins-8.4.5-1.el8.aarch64.rpm 

#libs
rpm -ivh mysql-community-libs-8.4.5-1.el8.aarch64.rpm 

#client
rpm -ivh mysql-community-client-8.4.5-1.el8.aarch64.rpm 

#icu-data
rpm -ivh mysql-community-icu-data-files-8.4.5-1.el8.aarch64.rpm 

#server 
rpm -ivh mysql-community-server-8.4.5-1.el8.aarch64.rpm

修改配置文件/etc/my.conf

port=9068
character-set-server=utf8
default-storage-engine=MyIsam
max_connections=1000
collation-server=utf8_unicode_ci
innodb_buffer_pool_size=64M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=120
innodb_log_buffer_size=4M
innodb_log_file_size=256M
interactive_timeout=120
join_buffer_size=2M
key_buffer_size=32M
max_allowed_packet=16M
max_heap_table_size=64M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=512kb
read_rnd_buffer_size=4M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=120
lower_case_table_names=1 #使用大小写不敏感
mysql_native_password=ON #激活旧版密码插件,不激活也可以

安装完成,初始化

mysqld --initialize --console --user=mysql --lower-case-table-names=1

修改安装目录所属组,使其可以访问MySql

chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /var/run/mysqld/

启动服务

systemctl start mysqld

会默认给一个临时密码,查看一下

cat /var/log/mysqld.log | grep localhost

使用该临时密码登录

mysql -uroot -p
#输入密码

修改密码

alter user 'root'@'localhost' identified by 'Admin@123';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Admin@123';

FLUSH PRIVILEGES;

验证

# 推出
exit 

mysql -uroot -pAdmin@123

三、赋予远程链接权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
或
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

【拓展】

如果报错:MySQL ERROR 1064 (42000)的方法

首先确定mysql_native_password插件是否安装

INSTALL PLUGIN mysql_native_password SONAME 'mysql_native_password';
### 如果已经安装,会显示该插件已经存在

查看插件状态

show plugins;
#看看mysql_native_password插件的状态是不是ACTIVE,如果状态值为DISABLED则说明插件没有激活

激活插件,修改my.cnf 或 my.ini配置文件

[mysqld]
mysql_native_password=ON #添加此行
#不要添加default_authentication_plugin=mysql_native_password,否则mysql会无法启动。
lower_case_table_names = 1 #不区分大小写

重启mysql服务

systemctl restart mysqld.service

mysql命令行查看用户使用的插件

select user,host,plugin from mysql.user;

修改密码认证方式

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your password';

#刷新权限
FLUSH PRIVILEGES; 

【错误检查】

参考链接:https://www.cnblogs.com/youjianjiangnan/p/10259151.html

报错: 2025-06-17T10:38:42.715896Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, can't open lock file /var/run/mysqld/mysqlx.sock.lock'

报错:

2023-09-04T03:41:13.596534Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28-0kylin0.20.04.3k1) starting as process 1313438
2023-09-04T03:41:13.625439Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-09-04T03:41:14.046678Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-09-04T03:41:14.174364Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, can't create lock file /var/run/mysqld/mysqlx.sock.lock'
2023-09-04T03:41:14.316646Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-09-04T03:41:14.316760Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-09-04T03:41:14.317232Z 0 [ERROR] [MY-010273] [Server] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
2023-09-04T03:41:14.317280Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2023-09-04T03:41:14.317885Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-09-04T03:41:15.708324Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28-0kylin0.20.04.3k1)  (Ubuntu).

解决:删掉lock文件和sock文件,执行命令:

sudo chown -R mysql:mysql /var/run/mysqld/

 

报错:

2025-06-17T10:36:08.897509Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.

解决:删除数据文件

rm -rf /var/lib/mysql/

 

报错:2025-06-17T10:34:20.392074Z 0 [ERROR] [MY-000067] [Server] unknown variable 'default_authentication_plugin=mysql_native_password'.

解决:删除my.conf中的default_authentication_plugin=mysql_native_password

 

报错:2025-06-17T10:35:55.151621Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

解决:初始化命令错误

 

错误:2025-06-17T10:38:42.882562Z 0 [ERROR] [MY-010092] [Server] Can't start server: can't create PID file: Permission denied

解决: 无权限,授权上面的权限

posted @ 2025-06-17 19:31  森屿旅人丶  阅读(352)  评论(0)    收藏  举报