MySQL5.7二进制安装
1.下载
https://downloads.mysql.com/archives/community/
2.环境检查
没有安装libao的话,需要安装这个软件包
[root@localhost ~]# rpm -qa | grep libaio libaio-0.3.109-13.el7.x86_64
3.创建用户及组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/nologin mysql
4.清理环境
[root@localhost ~]# rpm -qa | grep mariadb mariadb-libs-5.5.64-1.el7.x86_64 [root@localhost ~]# yum remove mariadb-libs-5.5.64-1.el7.x86_64 已加载插件:fastestmirror, langpacks 正在解决依赖关系 --> 正在检查事务 ---> 软件包 mariadb-libs.x86_64.1.5.5.64-1.el7 将被 删除 --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要 --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 postfix.x86_64.2.2.10.1-7.el7 将被 删除 --> 解决依赖关系完成 依赖关系解决
5.上传解压
[root@localhost app]# tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
6.移动目录
[root@localhost app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
7.添加环境变量
可以配置 /etc/profile,也可以配置 ~/.bash_profile ,/etc/profile 是配置所有用户,后者是配置当前用户
[root@localhost app]# vi ~/.bash_profile
export PATH=/mysql/app/mysql/bin:$PATH
执行 source ~/.bash_profile生效
8、修改目录权限
[root@localhost mysql]# chown -R mysql:mysql /mysql
9、准备配置文件
vi /etc/my.cnf [mysqld] user=mysql basedir=/mysql/app/mysql datadir=/mysql/data socket=/tmp/mysql.sock server_id=6 port=3306 [mysql] socket=/tmp/mysql.sock
10、初始化
[root@localhost data]# mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data
总用量 0
[root@localhost data]# mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data
2022-09-16T23:46:22.313854Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-09-16T23:46:24.303479Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-09-16T23:46:24.542230Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-09-16T23:46:24.606236Z 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: c63907f4-3619-11ed-b1c6-000c29a1f1bb.
2022-09-16T23:46:24.610141Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-09-16T23:46:24.626279Z 1 [Note] A temporary password is generated for root@localhost: wwpq9/E5q=o+
11.编辑启动文件
注意修改
ExecStart=/mysql/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
vi /etc/systemd/system/mysqld.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) 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=/mysql/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE=5000
12.启动MySQL
[root@localhost lib]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html [root@localhost lib]# systemctl start mysqld [root@localhost lib]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since 六 2022-09-17 08:40:52 CST; 3s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 3961 (mysqld)
13、登陆修改密码
初始密码是第10步初始化的时候形成的。
[root@localhost ~]# mysql -uroot -p mysql> set password=PASSWORD('root'); Query OK, 0 rows affected, 1 warning (0.02 sec)
14、授权root用户远程登陆
mysql> select user,host from mysql.user; +---------------+-----------+ | user | host | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
15.测试远程连接
16、创建库用户
mysql> create database ca default charset utf8 collate utf8_general_ci; Query OK, 1 row affected (0.04 sec) mysql> create user 'zg'@'%' identified by 'za'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on ca.* to 'zg'@'%' identified by 'za'; Query OK, 0 rows affected, 1 warning (0.00 sec)