前言:因工作需要,整理Linux系统下安装MySQL5.6版本系列。
1.下载安装包
下载地址:https://downloads.mysql.com/archives/community/
下载安装包 :mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
参考下图下载安装包
2.卸载其他
[root@localhost ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.44-2.el7.x86_64
mariadb-server-5.5.44-2.el7.x86_64
mariadb-5.5.44-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.x86_64 mariadb-server-5.5.44-2.el7.x86_64 mariadb-5.5.44-2.el7.x86_64
[root@localhost ~]# rpm -qa |grep mariadb
3.解压建组
[root@localhost etc]# cd /usr/local/
[root@localhost local]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz...
100% 307219 KB 18071 KB/sec 00:00:17 0 Errors
-->安装包上传方式不必一样,能上传就行。
[root@localhost local]# ls
bin games lib libexec sbin src
etc include lib64 mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz share
[root@localhost local]# tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
......
[root@localhost local]# ls
bin include libexec sbin
etc lib mysql-5.6.30-linux-glibc2.5-x86_64 share
games lib64 mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz src
[root@localhost local]# mv mysql-5.6.30-linux-glibc2.5-x86_64 mysql
[root@localhost local]# ls
bin games lib libexec mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz share
etc include lib64 mysql sbin src
[root@localhost local]# groupadd mysql
groupadd: group 'mysql' already exists
[root@localhost local]# useradd –g mysql mysql
4.修改my.cnf(可直接复制我的,有其他要求的请自行添加修改)
[root@localhost local]# vi /etc/my.cnf
[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
port=3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
5.修改目录拥有者
[root@localhost local]# vi /etc/my.cnf
[root@localhost local]# mkdir /var/lib/mysql
[root@localhost local]# mkdir /var/lib/mysql/mysql
[root@localhost local]# chown -R mysql:mysql /var/lib/mysql/
[root@localhost local]# chown -R mysql:mysql /var/lib/mysql//mysql/
[root@localhost local]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql ./
6.安装部署
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2022-04-01 16:14:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
......
[root@localhost mysql]# chown -R mysql:mysql data
[root@localhost mysql]# chown 777 /etc/my.cnf
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]# vi /etc/profile
在文件最后添加如下信息:
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# source /etc/profile
7.登陆修改密码
[root@localhost mysql]# service mysqld start
Starting MySQL SUCCESS!
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password("yourpassword") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
[root@localhost mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
安装结束!