麒麟V10部署MySQL8.0.33

2024-08-07 13:47:02 浏览数 (1)

服务器信息

下载安装包

https://downloads.mysql.com/archives/community/

安装

解压安装包

代码语言:javascript复制
tar xf mysql-8.0.33-linux-glibc2.17-aarch64-minimal.tar.xz

mv mysql-8.0.33-linux-glibc2.17-aarch64-minimal /usr/local/mysql

创建数据目录、用户

代码语言:javascript复制
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql

mkdir /data/mysql
mkdir /var/log/mysql

chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
chown -R mysql.mysql /var/log/mysql

修改配置文件

代码语言:javascript复制
vim /etc/my.cnf

[client]
socket=/data/mysql/mysql.sock
default-character-set=utf8mb4

[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
innodb_file_per_table=on
character-set-server=utf8mb4
log-error=/var/log/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
default_authentication_plugin=mysql_native_password

数据库初始化

代码语言:javascript复制
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --default-authentication-plugin=mysql_native_password --initialize

初始化完成后,/var/log/mysql/mysql.log 会自动生成默认 root 密码

创建启动脚本

代码语言:javascript复制
vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
Type=notify
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
代码语言:javascript复制
systemctl enable --now mysqld
systemctl status mysqld

登录数据库修改默认密码

报错:ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords。

解决办法:

代码语言:javascript复制
# 修改配置文件 /etc/my.cnf,添加下面一行,重启数据库服务
skip-grant tables

# 进入数据库,查看 root 用户详细信息
mysql -uroot -p -S /data/mysql/mysql.sock
MySQL [(none)]> use mysql;
MySQL [(none)]> select * from user where user='root' G

# 把 password_expired 改为不过期
MySQL [(none)]> update user set password_expired='N' where user='root';
MySQL [(none)]> flush privileges;

# 删除 /etc/my.cnf 中的 skip-grant tables

# 重启数据库服务

# 再次登录 mysql 就正常了

麒麟v10只能安装 gclibc2.17,安装glibc2.28时,会初始化异常

0 人点赞