CentOS7 安装mysql5.7 glibc版,tar.gz,tar.xz

 一、说明

个人感觉,glibc版的,好配置多版本、多实例。同一版本也方便配置多实例。

mysql安装方式很多:

1.glibc版,tar.gz,tar.xz

CentOS7.7下二进制部署MySQL多版本多实例实战

2.yum安装

CentOS 8 安装 MySQL 5.7 或 MySQL 8

A Quick Guide to Using the MySQL Yum Repository

CentOS 8 安装MySQL 8.0

3.rpm安装

4.源码安装

5.tar包

二、下载地址

MySQL :: Download MySQL Community Server

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

三、安装MySQL5.7

1.上传,解压,重命名

[root@dev1 opt]# tar -xvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@dev1 opt]# mv mysql-5.7.30-linux-glibc2.12-x86_64 mysql-5.7.30

2.创建配置文件my.cnf

[root@dev1 opt]# cd mysql-5.7.30/
[root@dev1 mysql-5.7.30]# vi my.cnf

[client]
port=3305

[mysql]
default-character-set=utf8
 
[mysqld]
# MySQL服务器将监听的TCP/IP端口
port=3305

# 安装目录的路径。 通常相对于此解析所有路径。
basedir=/opt/mysql-5.7.30

# 数据库根目录的路径
datadir=/opt/mysql-5.7.30/data

# 创建新模式或表且未定义任何字符集时将使用的默认字符集
character-set-server=utf8

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

# MySQL服务器允许的最大并发会话数。
# 这些连接中的一个将保留给具有超级权限的用户,以允许管理员登录,即使已达到连接限制。
max_connections=151

# soket文件,本地连接时使用
socket=/opt/mysql-5.7.30/data/mysql.sock

# 建议禁用符号链接以防止各种安全风险
symbolic-links=0

# 错误日志
log-error=/opt/mysql-5.7.30/data/mysqld.log

# pid文件
pid-file=/opt/mysql-5.7.30/data/mysqld.pid

# 表名不区分大小写
lower_case_table_names=1

# 设置sql_mode
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3.创建用户

-s /sbin/nologin 指定用户登入后所使用的shell。默认值为/bin/bash。/sbin/nologin,无法使用shell

-M:不要自动建立用户的登入目录。

[root@dev1 mysql-5.7.30]#  useradd -s /sbin/nologin -M mysql
[root@dev1 mysql-5.7.30]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)

[root@dev1 mysql-5.7.30]# chown -R mysql.mysql /opt/mysql-5.7.30

4.初始化

--initialize-insecure 密码为空

[root@dev1 mysql-5.7.30]# /opt/mysql-5.7.30/bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql-5.7.30 --datadir=/opt/mysql-5.7.30/data
[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

5.创建service文件

[root@dev1 mysql-5.7.30]# vi /usr/lib/systemd/system/mysqld57.service

或  vi /etc/systemd/system/mysqld57.service

[Unit]
Description=MySQL Server 5.7
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql-5.7.30/bin/mysqld --defaults-file=/opt/mysql-5.7.30/my.cnf
LimitNOFILE = max_open_files

6.启动服务

[root@dev1 mysql-5.7.30]# systemctl start mysqld57
[root@dev1 mysql-5.7.30]# netstat -lntup|grep mysqld
tcp6       0      0 :::3305                 :::*                    LISTEN      6684/mysqld

7.设置自启动

[root@bogon mysql-5.7.30]# systemctl enable mysqld57
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld57.service to /usr/lib/systemd/system/mysqld57.service.

8.客户端登录

[root@dev1 log]# /opt/mysql-5.7.30/bin/mysql -S /opt/mysql-5.7.30/data/mysql.sock
mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.7.30    |
+-----------+
1 row in set (0.00 sec)

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3305  |
+---------------+-------+
1 row in set (0.01 sec)

[root@bogon mysql-5.7.30]# cd bin
[root@bogon bin]# ./mysql -uroot -p

如果报错

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

可尝试:mysql -uroot -h 127.0.0.1 -p
            ./mysql -uroot -h 127.0.0.1 -P 3305 -p

也可以这样处理

ln -s /opt/mysql-5.7.30/data/mysql.sock /tmp/mysql.sock

9.修改密码,允许远程登录

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> select user,authentication_string,host from user;
+---------------+-------------------------------------------+-----------+
| user          | authentication_string                     | host      |
+---------------+-------------------------------------------+-----------+
| root          |                                           | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
3 rows in set (0.05 sec)

mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)

四、主从复制

CentOS7 mysql5.7 主从复制

五、文档

MySQL 5.7 Reference Manual

2.2 Installing MySQL on Unix/Linux Using Generic Binaries

2.3.4.2 Creating an Option File

4.2.2.2 Using Option Files

5.1.2 Server Configuration Defaults

5.1.6 Server Command Options

5.1.7 Server System Variables (my.cnf中的属性的解释及默认值)

10.4 Connection Character Sets and Collations

16.1.6 Replication and Binary Logging Options and Variables (主从复制)

六、yum安装mysq5.7默认配置文件(配置参考)

my.cnf,后续做性能优化。

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

你可能感兴趣的:(mysql,mysql,linux,数据库)