银河麒麟V10安装MySQL5.7
环境:
操作系统:Kylin Linux Advanced Server release V10 (Sword)
数据库:mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
一、准备安装包
# MySQL5.7下载地址
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
二、开始安装MySQL数据库
# 检查创建MySQL用户组以及用户
[root@oqfyrvws ~]# groupadd mysql
[root@oqfyrvws ~]# useradd -r -g mysql mysql
# 上传MySQL安装包至任意目录或者下载
[root@oqfyrvws ~]# mkdir /opt/software
[root@oqfyrvws software]# cd /opt/software/
[root@oqfyrvws software]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 解压安装包
[root@oqfyrvws software]# tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 在目录下/usr/local/mysql/创建data目录
[root@oqfyrvws software]# mkdir /usr/local/mysql/data -p
# 解压完成后移动至/usr/local/mysql
[root@oqfyrvws software]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
# 更改MySQL目录下所有的目录文件夹所属组和用户以及权限
[root@oqfyrvws software]# chown -R mysql:mysql /usr/local/mysql
[root@oqfyrvws software]# chmod -R 755 /usr/local/mysql
# 修改MySQL的数据配置文件 ,修改完后内容如下
[root@oqfyrvws software]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/usr/local/mysql/data/mysql.sock
user=mysql
port=3306
character-set-server=utf8
#取消密码验证
# #skip-grant-tables
# #Disabling symbolic-links is recommended prevent assorted security risks
symbolic-links=0
# #skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/usr/local/mysql/data/mysql.sock
# 编译安装并初始化MySQL数据库,并记录初始化后末尾输出的默认密码
[root@oqfyrvws bin]# cd /usr/local/mysql/bin
[root@oqfyrvws bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2023-11-06T13:43:16.347906Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-11-06T13:43:16.566621Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-11-06T13:43:16.602672Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-11-06T13:43:16.658030Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 705e59e3-7caa-11ee-a9ba-52548060504d.
2023-11-06T13:43:16.658624Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-11-06T13:43:17.618541Z 0 [Warning] CA certificate ca.pem is self signed.
2023-11-06T13:43:18.052405Z 1 [Note] A temporary password is generated for root@localhost: dr3IBaUb!auF
[root@oqfyrvws bin]#
# 以上步骤执行完成后生产的临时密码
[Note] A temporary password is generated for root@localhost: dr3IBaUb!auF
# 添加开机自启并开启服务
[root@oqfyrvws bin]# cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@oqfyrvws bin]# chmod +x /etc/init.d/mysqld
[root@oqfyrvws bin]# /usr/lib/systemd/systemd-sysv-install enable mysqld
# 编辑环境变量文件,在开头空白处添加---标注的两行代码
[root@localhost bin]# vim /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
#------ 添加以下两行 -------
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
#-------------------------
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# 使环境变量生效
[root@oqfyrvws bin]# source /etc/profile
# 开启MySQL服务
[root@oqfyrvws bin]# systemctl start mysqld
# 查询服务状态
[root@oqfyrvws bin]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
Active: active (running) since Mon 2023-11-06 21:47:21 CST; 51s ago
Docs: man:systemd-sysv-generator(8)
Process: 5993 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
Tasks: 28
Memory: 180.4M
CGroup: /system.slice/mysqld.service
├─6004 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/oqfyrvws.vm.pid
└─6217 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/usr/local/mysql/data/oqfyrvws.vm.pid --socket=/usr/local/mysql/dat>
Nov 06 21:47:20 oqfyrvws.vm systemd[1]: Starting LSB: start and stop MySQL...
Nov 06 21:47:21 oqfyrvws.vm mysqld[5993]: Starting MySQL. SUCCESS!
Nov 06 21:47:21 oqfyrvws.vm systemd[1]: Started LSB: start and stop MySQL.
lines 1-14/14 (END)
# 使用默认密码登录数据库
[root@oqfyrvws bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@oqfyrvws bin]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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> status
--------------
mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using EditLine wrapper
Connection id: 4
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.28 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /usr/local/mysql/data/mysql.sock
Uptime: 2 min 52 sec
Threads: 1 Questions: 8 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 99 Queries per second avg: 0.046
--------------
mysql>
评论