Linux安装Mysql5.6

Linux安装Mysql5.6

𝓓𝓸𝓷 Lv6

Centos安装Mysql5.6

一、准备工作

1.删除系统存在的Mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
If you have previously installed MySQL using your operating system native
package management system, such as Yum or APT, you may experience
problems installing using a native binary. Make sure your previous MySQL
installation has been removed entirely (using your package management
system), and that any additional files, such as old versions of your data files,
have also been removed. You should also check for configuration files such as
/etc/my.cnf or the /etc/mysql directory and delete them.

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
2.操作系统依赖包

yum install libaio

3.查看glibc版本

ldd --version|head -1

4.下载二进制安装包
1
wget -c https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
5.安装步骤
1
2
3
4
5
6
7
8
9
10
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
6.Mysql目录结构
Directory Contents of Directory
bin, scripts mysqld server, client and utility programs
data Log files, databases
docs MySQL manual in Info format
man Unix manual pages
include Include (header) files
lib Libraries
share Miscellaneous support files, including error messages, sample configuration files, SQL for database installation
sql-bench Benchmarks

二、安装

1.创建用户和组
1
2
3
4
5
6
7
groupadd -g 10000 mysql 
useradd -r -g mysql -u 10000 -s /bin/false mysql

温馨提示: -r参数指的是创建系统用户,该用户没有登录权限。

# id mysql
uid=600(mysql) gid=600(mysql) groups=600(mysql)
2.解压安装包
1
2
3
4
# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

温馨提示:如果tar不支持z选项,则可以使用gunzip命令:
gunzip < mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz |tar xvf -
3.创建软件链接
1
2
# cd /usr/local/
# ln -s mysql-5.6.36-linux-glibc2.5-x86_64 mysql
4.初如化目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# cd mysql

# scripts/mysql_install_db --user=mysql --random-passwords

# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --random-passwords

Mysql5.6初始化目录后,在basedir目录下生成my.cnf参数文件,同时data目录会自动授予mysql权限
随机密码: more /root/.mysql_secret

二进制安装和源码安装必须初始化数据。初始化包括mysql数据库的系统表。初始化目录是在第一次安装Mysql的时候执行,如果系统已经安装过Mysql,则使用mysql_upgrade代替。初始化目录不会覆盖任何存在的权限表,因此执行初始化脚本是安全的。初始化还可以指定--basedir参数和--datadir参数。另外:最好不要使用./mysql_install_db执行

# ll /usr/local/mysql/data/
total 110604
-rw-rw---- 1 mysql mysql 12582912 Jan 10 04:38 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jan 10 04:38 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jan 10 04:38 ib_logfile1
drwx------ 2 mysql mysql 4096 Jan 10 04:38 mysql
drwx------ 2 mysql mysql 4096 Jan 10 04:38 performance_schema
drwxr-xr-x 2 mysql mysql 4096 Jan 10 04:36 test
5.配置my.cnf参数文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# vi /etc/my.cnf

[mysqld]

bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid

#character config
character_set_server=utf8mb4
symbolic-links=0

[mysql]
socket=/tmp/mysql.sock
6.添加PATH环境变量
1
2
3
4
5
6
7
8
9
10
11
12
# vim /etc/profile

export PATH=/usr/local/mysql/bin:$PATH

温馨提示: 也可以使用sed命令添加

# sed -i '\$a export PATH=/usr/local/mysql/bin:$PATH\n' /etc/profile

# source /etc/profile

# tail -2 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
7.配置启动文件
1
# cp support-files/mysql.server /etc/init.d/mysql
8.启动Mysql
1
2
3
4
5
# mysqld_safe --user=mysql &

# /etc/init.d/mysql start

# service mysql start
启动命令 关闭命令
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
9.设置root密码
1
# mysqladmin -uroot   password '123456'
10.删除test库相关信息
1
# mysql_secure_installation
  • Title: Linux安装Mysql5.6
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-06-13 19:28:09
  • Updated at : 2025-01-08 09:49:29
  • Link: https://www.zhangdong.me/mysql5.6-installation.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论