麒麟V10(x86_64)安装部署MySQL-5.1.70
麒麟V10(x86_64)安装部署MySQL-5.1.70
1. 主机信息
[kalami@kysrv1 ~]$ uname -a
Linux kysrv1 4.19.90-24.4.v2101.ky10.x86_64 #1 SMP Mon May 24 12:14:55 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
[kalami@kysrv1 ~]$
[kalami@kysrv1 ~]$ uname -m
x86_64
[kalami@kysrv1 ~]$
[kalami@kysrv1 ~]$ uname -r
4.19.90-24.4.v2101.ky10.x86_64
[kalami@kysrv1 ~]$
[kalami@kysrv1 ~]$
[kalami@kysrv1 ~]$ lscpu
架构: x86_64
CPU 运行模式: 32-bit, 64-bit
字节序: Little Endian
Address sizes: 45 bits physical, 48 bits virtual
CPU: 4
在线 CPU 列表: 0-3
每个核的线程数: 1
每个座的核数: 2
座: 2
NUMA 节点: 1
厂商 ID: AuthenticAMD
CPU 系列: 25
型号: 80
型号名称: AMD Ryzen 5 PRO 5650U with Radeon Graphics
步进: 0
CPU MHz: 2295.689
BogoMIPS: 4591.37
超管理器厂商: VMware
虚拟化类型: 完全
L1d 缓存: 128 KiB
L1i 缓存: 128 KiB
L2 缓存: 2 MiB
L3 缓存: 32 MiB
NUMA 节点0 CPU: 0-3
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Full AMD retpoline, IBPB conditional, STIBP disabled, RSB filling
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
标记: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_ts
c rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid extd_apicid pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand
hypervisor lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rds
eed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero arat umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor
2. 卸载mariadb
先卸载系统自带的mariadb
数据库。
sudo yum autoremove mariadb mariadb-server
效果如下:
[root@kysrv1 support-files]# yum autoremove mariadb mariadb-server
依赖关系解决。
==============================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================
移除:
mariadb x86_64 3:10.3.9-9.p02.ky10 @anaconda 37 M
mariadb-server x86_64 3:10.3.9-9.p02.ky10 @anaconda 91 M
清除未被使用的依赖关系:
mariadb-common x86_64 3:10.3.9-9.p02.ky10 @anaconda 179 k
mariadb-errmessage x86_64 3:10.3.9-9.p02.ky10 @anaconda 2.3 M
perl-DBD-MySQL x86_64 4.046-6.ky10 @anaconda 333 k
事务概要
==============================================================================================================================================================================================
移除 5 软件包
将会释放空间:132 M
确定吗?[y/N]: y
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
运行脚本: mariadb-3:10.3.9-9.p02.ky10.x86_64 1/1
删除 : mariadb-3:10.3.9-9.p02.ky10.x86_64 1/5
运行脚本: mariadb-server-3:10.3.9-9.p02.ky10.x86_64 2/5
删除 : mariadb-server-3:10.3.9-9.p02.ky10.x86_64 2/5
警告:文件 /var/lib/mysql:移除失败:没有那个文件或目录
警告:文件 /run/mariadb:移除失败:没有那个文件或目录
运行脚本: mariadb-server-3:10.3.9-9.p02.ky10.x86_64 2/5
删除 : mariadb-errmessage-3:10.3.9-9.p02.ky10.x86_64 3/5
删除 : mariadb-common-3:10.3.9-9.p02.ky10.x86_64 4/5
删除 : perl-DBD-MySQL-4.046-6.ky10.x86_64 5/5
运行脚本: perl-DBD-MySQL-4.046-6.ky10.x86_64 5/5
验证 : mariadb-3:10.3.9-9.p02.ky10.x86_64 1/5
验证 : mariadb-common-3:10.3.9-9.p02.ky10.x86_64 2/5
验证 : mariadb-errmessage-3:10.3.9-9.p02.ky10.x86_64 3/5
验证 : mariadb-server-3:10.3.9-9.p02.ky10.x86_64 4/5
验证 : perl-DBD-MySQL-4.046-6.ky10.x86_64 5/5
已移除:
mariadb-3:10.3.9-9.p02.ky10.x86_64 mariadb-common-3:10.3.9-9.p02.ky10.x86_64 mariadb-errmessage-3:10.3.9-9.p02.ky10.x86_64 mariadb-server-3:10.3.9-9.p02.ky10.x86_64
perl-DBD-MySQL-4.046-6.ky10.x86_64
完毕!
[root@kysrv1 support-files]#
删除 /etc/my.cnf.d
目录:
rm -rf /etc/my.cnf.d
3. 安装MySQL-5.1.70
[1]. 下载二进制安装包
下载地址: MySQL :: Download MySQL Community Server (Archived Versions)
下载 "Compressed TAR Archive"
包。
[2]. 创建组和用户
创建组和用户
groupadd dba
useradd -g dba -m mysql
设置新用户密码
passwd mysql
[3]. 上传安装包并解压
C:\Users\kalami\Downloads>scp mysql-5.1.70-linux-x86_64-glibc23.tar.gz mysql@192.168.58.145:/home/mysql/
Authorized users only. All activities may be monitored and reported.
mysql@192.168.58.145's password:
mysql-5.1.70-linux-x86_64-glibc23.tar.gz 100% 128MB 150.0MB/s 00:00
C:\Users\kalami\Downloads>
上传完后,用如下命令解包:
$ tar xvfz mysql-5.1.70-linux-x86_64-glibc23.tar.gz
将mysql-5.1.70-linux-x86_64-glibc23
下的内容移到 /home/mysql/
目录下。
cd mysql-5.1.70-linux-x86_64-glibc23/
mv * ../
cd ..
rm -rf mysql-5.1.70-linux-x86_64-glibc23
[mysql@kysrv1 ~]$ pwd
/home/mysql
[mysql@kysrv1 ~]$ ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
[mysql@kysrv1 ~]$
[4]. 设置环境变量
以root
用户执行如下语句:
echo "PATH=/home/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
echo "LD_LIBRARY_PATH=/home/mysql/lib/mysql:$LD_LIBRARY_PATH" >> /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
[5]. 配置my.cnf文件
从源码包/home/mysql/support-files/my-small.cnf
拷贝一份,复制到/etc/my.cnf
。
sudo cp /home/mysql/support-files/my-small.cnf /etc/my.cnf
编辑 /etc/my.cnf
配置文件:
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
pid-file = /var/run/mysql/mysql.pid
log-error = /var/log/mysql/kysrv1_err.log
在[mysqld]
下增加如上内容(my.cnf
文件37行左右),修改后的内容如下:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
basedir = /home/mysql
datadir = /home/mysql/data
pid-file = /var/run/mysql/mysql.pid
log-error = /var/log/mysql/kysrv1_err.log
创建对应目录
以root
用户执行。
mkdir -p /var/run/mysql
mkdir -p /var/log/mysql
chown mysql /var/run/mysql
[6]. 初始化
以root
用户执行如下语句:
./scripts/mysql_install_db --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql
执行效果如下:
[mysql@kysrv1 ~]$ pwd
/home/mysql
[mysql@kysrv1 ~]$
[mysql@kysrv1 ~]$
[mysql@kysrv1 ~]$ su
密码:
[root@kysrv1 mysql]# ./scripts/mysql_install_db --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/home/mysql/bin/mysqladmin -u root password 'new-password'
/home/mysql/bin/mysqladmin -u root -h kysrv1 password 'new-password'
Alternatively you can run:
/home/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /home/mysql ; /home/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /home/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /home/mysql/scripts/mysqlbug script!
[root@kysrv1 mysql]#
[7]. 修改mysqld_safe脚本
先备份 /home/mysql/bin/mysqld_safe
脚本。
cp mysqld_safe mysqld_safe_bak
修改 /home/mysql/bin/mysqld_safe
脚本,将 "/usr/local/mysql"
替换成 "/home/mysql"
。
可以在 vi
编辑模式下,执行如下替换命令:
%s#/usr/local/mysql#/home/mysql#g
[8]. 配置启动脚本,并启动服务
[root@kysrv1 mysql]# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@kysrv1 mysql]# chmod +x /etc/init.d/mysqld
[root@kysrv1 mysql]#
#设置开机自启
[root@kysrv1 mysql]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable mysqld
[root@kysrv1 mysql]#
其他命令
#启动服务
[root@kysrv1 mysql]# service mysqld start
Starting MySQL. ERROR! Manager of pid-file quit without updating file.
[root@kysrv1 mysql]#
#查看服务状态
[root@kysrv1 mysql]# service mysqld status
ERROR! MySQL is not running, but lock exists
[root@kysrv1 mysql]#
#停止服务
[root@kysrv1 mysql]# service mysqld stop
4. 使用MySQL-5.1.70
[1]. 配置环境变量
配置环境变量之后,可以在任何用户目录下都可以使用MySQL
了。编辑/etc/profile
文件,增加如下内容:
export PATH=/home/mysql/bin:$PATH
export LD_LIBRARY_PATH=/home/mysql/lib/mysql:$LD_LIBRARY_PATH
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.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostnamectl --transient 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
if [ -n "${BASH_VERSION-}" ] ; then
if [ -f /etc/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bashrc
# Check for double sourcing is done in /etc/bashrc.
. /etc/bashrc
fi
fi
export PATH=/home/mysql/bin:$PATH
export LD_LIBRARY_PATH=/home/mysql/lib/mysql:$LD_LIBRARY_PATH
使参数生效,执行如下命令:
[root@kysrv1 mysql]# source /etc/profile
[2]. 设置密码
[root@kysrv1 mysql]# mysqladmin -u root password 'root123'
设置完用户密码后,再去登录验证。运行效果如下:
[root@kysrv1 mysql]# mysqladmin -u root password 'root123'
[root@kysrv1 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@kysrv1 mysql]#
[root@kysrv1 mysql]#
[root@kysrv1 mysql]# mysql -uroot -proot123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.70 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
[3]. 麒麟运行效果
[4]. 服务后台启动方法
如果将MySQL
服务以后台启动方式运行,则可以使用mysqld_safe
启动脚本。
sudo /home/mysql/bin/mysqld_safe --user=mysql &
[root@kysrv1 ~]# /home/mysql/bin/mysqld_safe --user=mysql &
[1] 3507
[root@kysrv1 ~]# 240826 21:16:04 mysqld_safe Logging to '/var/log/mysql/kysrv1_err.log'.
240826 21:16:04 mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
[root@kysrv1 ~]#
[5]. 故障排查
如果出现启动故障,则通过查看 /var/log/mysql/kysrv1_err.log
日志内容进行排查。