我用的是CentOS 7的操作系统来操作的,以下教程同样适用于银河麒麟v10的系统,要注意glibc的版本和一些命令格式即可。
1.安装前的环境检查
如果服务器上面有mariadb数据库会导致安装MySQL时,安装失败,所以安装前要先把mariadb给卸载掉。
[root@localhost ~]# getconf -a | grep glibc # 查看本机的glibc的版本
GNU_LIBC_VERSION glibc 2.17
[root@localhost ~]# rpm -qa | grep -i mariadb # 查看本机是否安装了mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# find / -name mariadb # 查看关于mariadb的文件
[root@localhost ~]# rpm -qa | grep -i mysql # 查看本机是否安装了mysql
[root@localhost ~]# find / -name mysql # 查看关于mysql的文件
[root@localhost ~]# yum remove mariadb-libs-5.5.68-1.el7.x86_64 # 删除mariadb
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 删除
***********
删除:
mariadb-libs.x86_64 1:5.5.68-1.el7
作为依赖被删除:
postfix.x86_64 2:2.10.1-9.el7
完毕!
2.安装MySQL8.0
2.1、下面是在官网找包的教程
2.2、如果你的服务器是可以通互联网状态的话可以直接下载到服务器。
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
--2024-12-05 10:40:07-- https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 2.19.153.220, 2600:1417:4400:8b6::1d68, 2600:1417:4400:8ae::1d68
正在连接 cdn.mysql.com (cdn.mysql.com)|2.19.153.220|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:52156212 (50M) [text/plain]
正在保存至: “mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz”
100%[============================================================================================================================================>] 52,156,212 1.17MB/s 用时 31s
2024-12-05 10:40:40 (1.59 MB/s) - 已保存 “mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz” [52156212/52156212])
[root@localhost ~]# ls
mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
2.3、包有了之后就可以开始部署了
[root@localhost ~]# tar -xvf mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
[root@localhost ~]# mv mysql-8.0.27-linux-glibc2.17-x86_64-minimal /usr/local/mysql && cd /usr/local/mysql
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# mkdir -p /usr/local/mysql/data/
[root@localhost mysql]# chown mysql:mysql -R /usr/local/mysql/
2.4、编写配置文件
[root@localhost mysql]# vim /etc/my.cnf
[client-server]
include all files from the config directory
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
max_connections=3001
lower_case_table_names=1 # 如果需要区分大小写,需要将此处设置为0,此处为1表示不区分大小写
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENG
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
2.5、 初始化数据库
[root@localhost mysql]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
[root@localhost bin]# cat /usr/local/mysql/data/mysql.err
2024-12-05T03:13:46.341585Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2024-12-05T03:13:46.341646Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 26962
2024-12-05T03:13:46.346840Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-12-05T03:13:46.652782Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-12-05T03:13:47.174183Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2024-12-05T03:13:47.174195Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2024-12-05T03:13:47.197441Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cp<NRDj9tZN_
注意:初始密码是在mysql.err的日志中的
2.6、启动数据库
[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost bin]# service mysql start
Starting MySQL. SUCCESS!
2.7、验证一下
[root@localhost bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
好,到这里数据库安装完成,但是初试密码会过期,要及时修改
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Aa@123456';
Query OK, 0 rows affected (0.00 sec)
=========================================================================
以上参考博客:https://blog.csdn.net/2401_83087698/article/details/144256511
注意:在 MySQL 8.0 中,直接使用 GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '12345678'; 会报错,因为 MySQL 8.0 修改了权限管理机制,不再允许在 GRANT 语句中直接设置密码。
1、安装文档中,mysql不包含密码认证策略,单独安装
1.1、检查插件状态
SELECT plugin_name, plugin_status FROM information_schema.plugins WHERE plugin_name = 'validate_password';
1.2、如果未安装,手动加载
INSTALL PLUGIN validate_password SONAME 'validate_password.so';
注意:如果报错 ERROR 1126 (HY000): Can't open shared library,说明 MySQL 未包含该插件,需从其他来源获取或编译安装。
1.3、编辑 MySQL 配置文件
sudo vi /etc/my.cnf
在 [mysqld] 段添加:
plugin-load-add = validate_password.so
validate-password = FORCE_PLUS_PERMANENT
重启mysql
sudo systemctl restart mysqld
1.4、再次检查插件
SELECT plugin_name, plugin_status FROM information_schema.plugins WHERE plugin_name = 'validate_password';
1.5、检查变量
SHOW VARIABLES LIKE 'validate_password%';
正常应该输出:
2、创建新的用户
CREATE USER 'username'@'%' IDENTIFIED BY 'Aaaaa_2025';
2.1、赋予所有访问权限
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
2.2、刷新权限
flush privileges;
注意:使用工具连接时报错:2059 - Authentication plugin 'caching sha2 password' cannot be loaded: ◆X@◆◆參◆◆◆g◆願
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'Aaaaa_2025';
刷新权限
flush privileges;
3、修改默认支持大小写
3.1、先停止数据库服务
sudo systemctl stop mysqld
3.2、my.cnf配置文件添加参数(如果存在参数、则修改参数值即可)
lower_case_table_names=0
3.3、初始化时设置为参数为0
sudo mysqld --initialize --user=mysql --lower-case-table-names=0
3.4、检查是否生效
SHOW VARIABLES LIKE 'lower_case_table_names';
感谢博主,喝杯咖啡~
感谢博主,喝杯咖啡~
还没有人发表评论