MySQL5.7的tar包指定路径安装手册
使用wget 从官网下所需版本的tar包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
(1)在/root/xxx/目录下创建mysql-5.7目录
mkdir mysql-5.7
(2)将tar包解压至目标目录( /root/xxx/mysql-5.7)并改名为mysql
tar -zxvf xxx /root/xxx/mysql-5.7
mv xxx mysql
(3)在此目录下创建数据库文件目录(data)
mkdir /root/xxx/mysql-5.7/data
(4)创建mysql组和用户
groupadd mysql
useradd -r -g mysql mysql
(5)更改当前目录下文件夹的所属组和用户
chown -R mysql:mysql ./mysql
chown -R mysql:mysql ./data
(6)进入/root/xxx/mysql-5.7/mysql/support-files文件夹, 手动创建my_default.cnf文件
touch my_default.cnf
(7)配置my_default.cnf文件(最简化配置)
[client]
socket = /root/xxx/mysql-5.7/data/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/root/xxx/mysql-5.7/mysql
datadir=/root/xxx/mysql-5.7/data
socket=/root/xxx/mysql-5.7/data/mysql.sock
lower_case_table_names = 1
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_F OR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/root/xxx/mysql-5.7/data/mysqld.log
pid-file=/root/xxx/mysql-5.7/data/mysqld.pid
(8)将目录下的my_default.cnf,mysql.server分别复制到/etc和/etc/init.d下改名为my.cnf和mysqld(/etc/my.cnf如果存在覆盖即可)
cp /root/xxx/mysql-5.7/mysql/support-files/my_default.cnf /etc/my.cnf
cp /root/xxx/mysql-5.7/mysql/support-files/mysql.server /etc/init.d/mysqld
(9)进入bin目录,进行注册和初始化Mysql服务
./mysqld --initialize-insecure --user=mysql -- basedir=/root/xxx/mysql-5.7/mysql -- datadir=/root/xxx/mysql-5.7/data
说明:安装时可能会有如下报错:
mysqld: Can't change dir to 'D:\MySQL\MySQL Server 5.7\data\' (Errcode: 13 - Permission denied) 报错为权限不足
解决办法:
使用命令chmod 777 /root即可(每次重装时,需要删除data文件夹下的所有文件.)
/etc/init.d/mysqld strat
/root/xxx/mysql-5.7/mysql/bin/mysql -uroot -p
初始化后应该没有密码,直接回车进入即可
若提示需要密码使用命令查看data文件夹下mysqld.log日志,寻找临时密码: grep 'temporary password' ./mysqld.log
进入mysql后修改root密码:
SET PASSWORD = PASSWORD(‘akazam’);
刷新权限:
flush privileges;
grant all privileges on *.* to root@’%’ identified by ‘akazam’;