01-Mysql-安装

114 阅读3分钟

1.软件安装

下载地址:Mysql下载地址

image.png

2.解压缩

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

3.配置PATH

1.做个软链接,便于二进制包的升级,后续的使用路径,用的都是软连接

ln -s /opt/mysql-5.7.28-linux-glibc2.12-x86_64   /opt/mysql
ls /opt/ -l

lrwxrwxrwx 1 mysql mysql        40 Aug 29 17:18 /opt/mysql -> /opt/mysql-5.7.26-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql      4096 Aug 29 17:14 /opt/mysql-5.7.26-linux-glibc2.12-x86_64
-rw-r--r-- 1 mysql mysql 644869837 Aug 29 17:09 /opt/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

2.配置PATH

echo 'export PATH=$PATH:/opt/mysql/bin'  >> /etc/profile
source /etc/profile

3.验证mysql版本

[root@VM-4-8-centos opt]# mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

4.删除mariadb的依赖,删除默认的配置文件

yum remove mariadb-libs.x86_64  -y
rm -f /etc/my.cnf

5.装mysql5.7特有的依赖包

yum install libaio-devel -y

如果遇到安装不上的情况,例如这种

image.png 重新添加一下数据源:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

6. 创建数据目录,准备mysql的数据目录,授权用户

useradd -s /sbin/nologin -M mysql
mkdir -p /linux0224/
mkdir -p /linux0224/mysql_3306/
chown -R mysql.mysql /linux0224/
chown -R mysql.mysql /linux0224/mysql_3306/
chown -R mysql.mysql /opt/mysql*

[root@VM-4-8-centos /]# ls -l linux0224/
total 4
drwxr-xr-x 2 mysql mysql 4096 Aug 29 17:26 mysql_3306
[root@VM-4-8-centos /]# ls -ld  /linux0224 /linux0224/mysql_3306/  /opt/mysql*
drwxr-xr-x 3 mysql mysql      4096 Aug 29 17:26 /linux0224
drwxr-xr-x 2 mysql mysql      4096 Aug 29 17:26 /linux0224/mysql_3306/
lrwxrwxrwx 1 mysql mysql        40 Aug 29 17:18 /opt/mysql -> /opt/mysql-5.7.26-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql      4096 Aug 29 17:14 /opt/mysql-5.7.26-linux-glibc2.12-x86_64
-rw-r--r-- 1 mysql mysql 644869837 Aug 29 17:09 /opt/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

7. 始化生成mysql默认库的数据源 ,用户等信息,即可启动

mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/linux0224/mysql_3306/

8. 新增配置文件

cat >/etc/my.cnf <<'EOF'
[mysqld]
port=3306
user=mysql
basedir=/opt/mysql
datadir=/linux0224/mysql_3306/
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF

8. 启动脚本


cp /opt/mysql/support-files/mysql.server   /etc/init.d/mysqld
systemctl daemon-reload

systemctl status mysqld
[root@VM-4-8-centos /]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
     
systemctl start mysqld

systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Thu 2024-08-29 17:29:25 CST; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18846 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    Tasks: 28
   Memory: 202.6M
   CGroup: /system.slice/mysqld.service
           ├─18861 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/linux0224/mysql_3306/ --pid-file=/linux0224/mysql_3306//VM-4-8-centos.pid
           └─19015 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/linux0224/mysql_3306 --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=VM-4-8...

Aug 29 17:29:24 VM-4-8-centos systemd[1]: Starting LSB: start and stop MySQL...
Aug 29 17:29:24 VM-4-8-centos mysqld[18846]: Starting MySQL.Logging to '/linux0224/mysql_3306/VM-4-8-centos.err'.
Aug 29 17:29:25 VM-4-8-centos mysqld[18846]: SUCCESS!
Aug 29 17:29:25 VM-4-8-centos systemd[1]: Started LSB: start and stop MySQL.

[root@VM-4-8-centos opt]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 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>