Linux安装Mysql5.6
一、准备工作
1.配置Yum
1 | [root@mysql opt]# cp -r /run/media/admin/CentOS\ 7\ x86_64/* /opt/yum |
2.操作系统依赖包
For MySQL 5.7.19 and later: Support for Non-Uniform Memory Access
(NUMA) has been added to the generic Linux build, which has a dependency
now on the libnuma library; if the library has not been installed on your
system, use you system’s package manager to search for and install it (see
the preceding item for some sample commands).SLES 11: As of MySQL 5.7.19, the Linux Generic tarball package format is
EL6 instead of EL5. As a side effect, the MySQL client bin/mysql needs
libtinfo.so.5.
A workaround is to create a symlink, such asln -s libncurses.so.5.6 /lib64/libtinfo.so.5 on 64-bit systems or
ln-s libncurses.so.5.6 /lib/libtinfo.so.5 on 32-bit systems.
1 | [root@mysql soft]# yum install libaio |
3.二进制安装包
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
4.安装步骤
1 | shell> groupadd mysql |
5.Mysql目录结构
| Directory | Contents of Directory |
|---|---|
bin |
mysqld 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 |
二、安装
安装前检查:
[root@mysql mysql]# rpm -qa |grep mysql
[root@mysql mysql]# rpm -qa |grep mariadb磁盘挂载:
[root@mysql soft]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0[root@mysql soft]# blkid
/dev/sda1: UUID=”28c5912e-d7ae-4c5f-a404-f1806d48ca93” TYPE=”xfs”
/dev/sda2: UUID=”VczXPR-tZhP-TR58-NYzW-3hsR-F3Qc-TzTaO6” TYPE=”LVM2_member”
/dev/sr0: UUID=”2020-11-04-11-36-43-00” LABEL=”CentOS 7 x86_64” TYPE=”iso9660” PTTYPE=”dos”
/dev/sdb: UUID=”804f4903-7d62-4669-b48a-5add1d0d2312” TYPE=”xfs”
/dev/mapper/centos-root: UUID=”6947bf69-372b-4127-b1c9-287c133c0090” TYPE=”xfs”[root@mysql soft]# vi /etc/fstab
UUID=”804f4903-7d62-4669-b48a-5add1d0d2312” /data xfs defaults 0 0
[root@mysql soft]# mount -a
1.卸载Mariadb
1 | [root@mysql mysql]# rpm -qa |grep mariadb |
2.创建用户和组
groupadd -g 600 mysql
useradd -r -g mysql -u 600 -s /bin/false mysql
温馨提示: -r参数指的是创建系统用户,该用户没有登录权限。
[root@mysql ~]# id mysql
uid=600(mysql) gid=600(mysql) groups=600(mysql)
3.解压安装包
[root@mysql soft]# tar zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
温馨提示:如果tar不支持z选项,则可以使用gunzip命令
gunzip < mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz |tar xvf -
4.创建软件链接
[root@mysql soft]# cd /usr/local/
[root@mysql local]# ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql
5.添加PATH环境变量
[root@mysql mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
温馨提示: 也可以使用sed命令添加
[root@mysql mysql]# sed -i ‘$a export PATH=/usr/local/mysql/bin:$PATH\n’ /etc/profile
[root@mysql mysql]# source /etc/profile
[root@mysql mysql]# tail -2 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
6.创建数据文件目录
[root@mysql soft]# cd /usr/local/mysql
[root@mysql mysql]# mkdir mysql-files
[root@mysql mysql]# chown mysql:mysql mysql-files
[root@mysql mysql]# chmod 750 mysql-files
7.初如化目录
如果初始化报如下错误:
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
则安装以下包即可:
yum install libaio-devel
[root@mysql mysql]# mysqld –initialize –user=mysql
2018-01-10T01:53:32.293392Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-10T01:53:32.718329Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-01-10T01:53:32.786439Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-01-10T01:53:32.859312Z 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: 1039d2a7-f5a9-11e7-be37-0800273f185b.
2018-01-10T01:53:32.860393Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-01-10T01:53:32.861180Z 1 [Note] A temporary password is generated for root@localhost: djqWilKg>5t9
–initialize生成一个临时密码:
密码12位数字,4种字符组合
密码有效期180天
如果不想使用这种密码复杂策略,可以使用–initialize-insecure
1 | 初次安装Mysql5.7以上版本后初始root密码找不到的问题 |
8.配置SSL支持
1 | [root@mysql mysql]# mysql_ssl_rsa_setup |
分配权限:
chown mysql:mysql *.pem
9.配置my.cnf参数文件
Mysql my.cnf:
cat > /etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF
[root@mysql mysql]# cp my.cnf /etc/
10.配置启动文件
两种启动方式:
- sys-v
1 | cp support-files/mysql.server /etc/init.d/mysqld |
- systemd
1 | cat >/etc/systemd/system/mysqld.service <<EOF |
11.Mysql启动
[root@mysql ~]# mysqld_safe –user=mysql &
| 启动命令 | 关闭命令 |
|---|---|
| mysqld –user=mysql & | mysqladmin -uroot -p shutdown |
| mysqld_safe –user=mysql & | mysqladmin -uroot -p shutdown |
| /etc/init.d/mysql start | /etc/init.d/mysql stop |
判断Mysql是否启动:
netstat -lnp |grep 3306
ps -ef |grep mysql
12.创建root密码
[root@mysql ~]# mysqladmin -uroot -p password ‘123456’
13.root密码忘记解决方法
–skip-grant-tables #跳过授权表
–skip-networking #跳过远程登录
1.关闭数据库
2.mysqld_safe –user=mysql –skip-grant-tables –skip-networking &
或者修改/etc/my.cnf增加这两个参数
3.登录数据库update mysql.user表
1 |
|
4.关闭数据库
5.重启数据库
如果修改的my.cnf,则修改root密码后,一定要将my.cnf去掉参数–skip-grant-tables –skip-networking
14.删除test库相关信息
[root@mysql ~]# mysql_secure_installation
- Title: Linux安装Mysql5.6
- Author: 𝓓𝓸𝓷
- Created at : 2024-08-12 20:18:37
- Updated at : 2025-01-08 10:13:39
- Link: https://www.zhangdong.me/mysql5.7-installation.html
- License: This work is licensed under CC BY-NC-SA 4.0.
