官方下载地址:https://downloads.mysql.com/archives/community/
官方文档:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
文章目录
检查系统中的Mysql或Mariadb
[root@mysqldb mysql-5.7]# rpm -qa | grep mysql
[root@mysqldb mysql-5.7]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@mysqldb mysql-5.7]# yum -y remove mariadb-libs.x86_64
创建Mysql用户
官方使用的是/bin/false一样也可以。
[root@mysqldb ~]# useradd -M -s /sbin/nologin -r mysql
# -M不创建主目录,-s /sbin/nologin不允许登录,-r创建的是系统用户
安装依赖包
CentOS7 自带可以不装。
yum install libaio
- 官方说明:版本大于等于5.7.19,对通用Linux构建添加了对非统一内存访问(NUMA)的支持,该构建现在依赖于
libnuma
库。
准备初始化
[root@mysqldb ~]# mkdir /data/ # 创建目录
[root@mysqldb ~]# tar zxf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /data/
[root@mysqldb ~]# mv /data/mysql-5.7.33-linux-glibc2.12-x86_64 /data/mysql-5.7
[root@mysqldb ~]# ln -s /data/mysql-5.7/ /usr/local/mysql # 创建软连接
[root@mysqldb data]# chown -R mysql.mysql /usr/local/mysql/ # 修改所属主所属组
初始化
最后一行是数据库密码
[root@mysqldb data]# cd /usr/local/mysql/
[root@mysqldb mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2021-06-09T08:41:20.731759Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-09T08:41:21.220041Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-06-09T08:41:21.320599Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-06-09T08:41:21.398421Z 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: 7751184d-c8fe-11eb-b2f7-000c29d938db.
2021-06-09T08:41:21.399751Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-06-09T08:41:22.656159Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-09T08:41:22.925994Z 1 [Note] A temporary password is generated for root@localhost: fUXEXqpBW2*r
编写配置文件
[root@mysqldb mysql]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock
配置环境变量
[root@mysqldb mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@mysqldb mysql]# . /etc/profile.d/mysql.sh # 刷新环境变量
# 还可以使用source /etc/profile.d/mysql.sh
生成启动脚本
[root@mysqldb mysql]# cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysqldb mysql]# chmod +x /etc/init.d/mysqld
[root@mysqldb mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql # 在第46~47行
datadir=/usr/local/mysql/data
[root@mysqldb mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@mysqldb mysql]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1327/sshd
tcp6 0 0 :::3306 :::* LISTEN 18475/mysqld
tcp6 0 0 :::22 :::* LISTEN 1327/sshd
测试链接并修改密码
[root@mysqldb mysql]# mysql -uroot -p'fUXEXqpBW2*r'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show bariables like 'validate_password%';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bariables like 'validate_password%'' at line 1
mysql> show variables like 'validate_password%';
Empty set (0.02 sec)
mysql> exit;
Bye
[root@mysqldb mysql]# mysql -uroot -p'123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> exit;
Bye
[root@mysqldb mysql]#
Systemd管理Mysql
[root@mysqldb ~]# cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
# 重新载入配置文件
[root@mysqldb ~]# systemctl status mysqld.service
最新评论
# 这只是一个创建远程登录并授权的语句、仅作为记录 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Fit2cloud!' WITH GRANT OPTION;
当MGR集群初始化结束后,需要开启MGR集群自启动(需要有一台节点是自动开启引导) loose-group_replication_start_on_boot = ON #设置节点是否在启动时自动启动 MGR 集群 loose-group_replication_bootstrap_group = ON #设置节点是否作为初始引导节点启动集群
密码:blog.sirliu.com
本内容密码:blog.sirliu.com 最新整理的文章在这里喔:https://blog.sirliu.com/2018/11/shell_lian_xi_ti.html