Linux安装Mysql8.0

Linux安装Mysql8.0

𝓓𝓸𝓷 Lv6

Centos7.9安装Mysql8.0(二进制)

MySQL :: MySQL 8.0 Reference Manual :: 2.2 Installing MySQL on Unix/Linux Using Generic Binaries

一、查看glibc版本
1
ldd --version|head -1
二、卸载旧的版本及配置文件
1
2
3
4
5
6
7
for i in $(rpm -qa|grep mysql);do rpm -e $i --nodeps;done

rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
rm -rf /usr/share/mysql
rm -rf /etc/my.cnf.d
rm -rf /etc/mysql
三、安装依赖的软件包
1
2
3
4
5
6
yum search libaio  # search for info

yum -y install libaio

# Oracle Linux 8 / Red Hat 8 (EL8): CentOS 8 mysql: error while loading shared libraries: libncurses.so.5
yum install ncurses ncurses-compat-libs -y
四、下载Mysql

Untitled

五、Mysql安装文件布局

Table 2.3 MySQL Installation Layout for Generic Unix/Linux Binary Package

Directory Contents of Directory
bin https://dev.mysql.com/doc/refman/8.0/en/mysqld.html server, client and utility programs
docs MySQL manual in Info format
man Unix manual pages
include Include (header) files
lib Libraries
share Error messages, dictionary, and SQL for database installation
support-files Miscellaneous support files
六、安装步骤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$> groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
$> cd /usr/local
$> tar xvf /path/to/mysql-VERSION-OS.tar.xz
$> ln -s full-path-to-mysql-VERSION-OS mysql
$> cd mysql
$> mkdir mysql-files
$> chown mysql:mysql mysql-files
$> chmod 750 mysql-files
$> bin/mysqld --initialize --user=mysql
$> bin/mysql_ssl_rsa_setup
$> bin/mysqld_safe --user=mysql &
# Next command is optional
$> cp support-files/mysql.server /etc/init.d/mysql.server

The mysql-files directory provides a convenient location to use as the value for the secure_file_priv system variable, which limits import and export operations to a specific directory.
See Section 5.1.8, “Server System Variables”.
七、创建用户及组

Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.

1
2
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
八、解压
1
2
3
4
5
tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /usr/local/

如果不想创建软链接,可以提前创建mysql文件夹,然后解压使用--strip-components参数将文件直接解压到/usr/local/mysql根目录:
mkdir /usr/local/mysql
tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysql --strip-components=1
九、创建软链接
1
2
3
4
cd /usr/local/
ln -s mysql-8.0.32-linux-glibc2.12-x86_64 mysql

chown -R root.root mysql/*
十、添加环境变量
1
2
3
4
# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin

# source /etc/profile
十一、初始化数据
1
2
3
4
5
6
7
# mkdir -p /data/mysql/3306/data

# mysqld --initialize --user=mysql --datadir=/data/mysql/3306/data



# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql/3306/data
十二、创建my.cnf

mysql5.7以后就没有my.cnf了,需要手工创建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data
character-set-server = utf8
user = mysql
port = 3306
socket = /data/mysql/3306/data/mysql.sock
server-id = 1

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

---设置权限
# chmod 664 /etc/my.cnf
十三、启动/关闭数据库

启动mysql可以采用sys-v或systemd两种方式启动

1.sys-v方式启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---创建启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

---启动Mysql
# /etc/init.d/mysql start
Starting MySQL.. SUCCESS

---关闭Mysql
# /etc/init.d/mysql stop
Shutting down MySQL.. SUCCESS!



# service mysql start
# service mysql stop



# mysqld_safe --user=mysql &
2.systemd方式启动
1
2
3
4
5
6
7
8
9
10
11
12
---创建启动脚本
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/init.d/mysql

---配置mysql开机自动启动
# chkconfig mysql on
# systemctl enable mysql

---启动与关闭mysql
# systemctl start mysql
# systemctl status mysql
# systemctl stop mysql
  • Title: Linux安装Mysql8.0
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-07-13 11:23:09
  • Updated at : 2025-01-08 08:55:39
  • Link: https://www.zhangdong.me/mysql8.0-installation.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论