博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽
二、MySQL安装(tar.gz)
1.系统环境设置
1.1清空系统mysql
安装mysql之前需要将系统自带的mysql包进行删除:
yum remove all mysql\*
1.2SELinux设置
vim /etc/selinux/config
输入:
disabled
reboot
getenforce
df -lh (确保拥有4G空间可用)
1.3创建目录
1.3.1安装目录
mkdir -p /var/lib/mysql5.7/
1.3.2数据文件
mkdir -p /var/lib/mysql5.7/data
mkdir -p /var/lib/mysql5.7/pid
1.3.3日志目录
mkdir -p /var/lib/mysql5.7/log
1.4设置时间同步
timedatectl set-timezone Asia/Shanghai
date
2. 二进制安装(tar.gz)
2.1赋权
chmod 755 mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
2.2解压
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /var/lib/mysql5.7/
cd /var/lib/mysql5.7/
ll
显示:
total 0
drwxr-xr-x 4 root root 29 Dec 19 08:59 mysql5.7.28
drwxr-xr-x 9 root root 129 Dec 19 09:18 mysql-5.7.28-linux-glibc2.12-x86_64
2.3改名
mv mysql-5.7.28-linux-glibc2.12-x86_64/ mysql5.7.28
cd /var/lib/mysql5.7/mysql5.7.28
2.4创建用户与组、安装与配置
参照1:mysql官方文档
下载连接:https://downloads.mysql.com/docs/refman-5.7-en.pdf
[root@mysql_slave mysql5.7]# pwd
/var/lib/mysql5.7
[root@mysql_slave mysql5.7]# cd mysql5.7.28
[root@mysql_slave mysql5.7.28]# groupadd mysql
[root@mysql_slave mysql5.7.28]# useradd -r -g mysql -s /bin/false mysql
[root@mysql_slave mysql5.7.28]# chown -R mysql:mysql /var/lib/mysql5.7/mysql5.7.28
[root@mysql_slave mysql5.7.28]# mkdir mysql-files
[root@mysql_slave mysql5.7.28]# chown mysql:mysql mysql-files
[root@mysql_slave mysql5.7.28]# chmod 750 mysql-files
[root@mysql_slave mysql5.7.28]# bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql5.7/mysql5.7.28 --datadir=/var/lib/mysql5.7/data
2019-12-19T15:50:33.579346Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-19T15:50:33.867664Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-19T15:50:33.924879Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-19T15:50:33.984959Z 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: 4ad074ce-2277-11ea-aef8-000c2926368f.
2019-12-19T15:50:33.985896Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-19T15:50:34.459641Z 0 [Warning] CA certificate ca.pem is self signed.
2019-12-19T15:50:34.729030Z 1 [Note] A temporary password is generated for root@localhost: e_opE5TIU:we (临时密码)
[root@mysql_slave mysql5.7.28]# echo $? (验证安装)
0
[root@mysql_slave mysql5.7.28]# vim /etc/my.cnf
修改两处:
[mysqld]
datadir=/var/lib/mysql5.7/data
socket=/var/lib/mysql5.7/data/mysql.sock
2.5启动服务
[root@mysql_slave mysql5.7.28]# bin/mysql_ssl_rsa_setup
[root@mysql_slave mysql5.7.28]# bin/mysqld_safe --user=mysql &
[root@mysql_slave mysql5.7.28]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@mysql_slave mysql5.7.28]# service mysql.server start
/etc/init.d/mysql.server: line 239: my_print_defaults: command not found
/etc/init.d/mysql.server: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
2.5.1依据报错提示,建立软连接:
[root@mysql_slave mysql5.7.28]# cd /usr/local/
[root@mysql_slave local]# ln -s /var/lib/mysql5.7/mysql5.7.28 mysql
(create a symbolic link to the installation directory created by tar)
[root@mysql_slave local]# cd -
/var/lib/mysql5.7/mysql5.7.28
[root@mysql_slave mysql5.7.28]# service mysql.server start
Starting MySQL.2019-12-19T15:55:39.340393Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/mysql_slave.pid).
2.5.2依据报错提示,设置日志目录:
[root@mysql_slave mysql5.7]# pwd
/var/lib/mysql5.7
[root@mysql_slave mysql5.7]# mkdir pid
[root@mysql_slave mysql5.7]# touch /var/lib/mysql5.7/log/mysql.log
[root@mysql_slave mysql5.7]# touch /var/lib/mysql5.7/pid/mysql.pid
[root@mysql_slave mysql5.7]# chown -R mysql:mysql .*
[root@mysql_slave mysql5.7]# vim /etc/my.cnf
修改两处:
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/var/lib/mysql5.7/log/mysql.log
#pid-file=/var/run/mariadb/mariadb.pid
pid-file=/var/lib/mysql5.7/pid/mysql.pid
[root@mysql_slave mysql5.7.28]# service mysql.server start
Starting MySQL SUCCESS! (看到这个是不是会有点高兴呢?)
2.6设置开机启动
chkconfig --add mysql.server
chkconfig --list
chkconfig mysql.server on
systemctl start mysqld/mysql.server
2.7修改密码
[root@mysql_slave ~]# /var/lib/mysql5.7/mysql5.7.28/bin/mysqld_safe --skip-grant-tables &
[root@mysql_slave mysql5.7.28]# mysql -uroot -p
-bash: mysql: command not found
2.7.1根据报错提示设置环境变量
[root@mysql_slave mysql5.7.28]# export PATH=$PATH:/usr/local/mysql/bin
[root@mysql_slave mysql5.7.28]# vim /etc/profile
输入:
export PATH=$PATH:/usr/local/mysql/bin
[root@mysql_slave mysql5.7.28]# source /etc/profil
[root@mysql_slave mysql5.7.28]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
2.7.2根据报错提示,建立sock软连接
[root@mysql_slave ~]# find / -name mysql.sock
/var/lib/mysql5.7/data/mysql.sock
/var/lib/mysql/mysql.sock
[root@mysql_slave ~]# rm -rf /tmp/*
[root@mysql_slave ~]# ln -s /var/lib/mysql5.7/data/mysql.sock /tmp/mysql.sock
此时方可重置密码:设置密码
[root@mysql_slave ~]# /var/lib/mysql5.7/mysql5.7.28/bin/mysqld_safe --skip-grant-tables &
空密码登录:
[root@mysql_slave ~]# mysql -uroot -p
Enter password: (enter)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
首次修改密码必须使用alter:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
后面再次修改密码可以使用其他方法:
mysql> update mysql.user set authentication_string=password('123456') where User='root';
mysql> flush privileges;
3.其它设置
3.1创建用户与数据库 (参考上一篇博文内容)
3.2授权访问 (参考上一篇博文内容)
原创内容,转载需注明出处
来源:oschina
链接:https://my.oschina.net/u/4328928/blog/3315352