[转至:https://blog.csdn.net/VI7591/article/details/102129979]
原文章中的第四步感觉放到后面处理,否则会数据库初始化失败。
下载mysql:
https://dev.mysql.com/downloads/mysql/
解压tar.xz文件:xz -d mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
1.解压包
tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar
mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql
yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
useradd -s /sbin/nologin mysql
4.初始化数据和指定安装目录和数据目录
/usr/local/mysql/bin/mysqld --initialize --console --skip-grant-tables --user=mysql --basedir=/usr/local/mysql/ --datadir=/mnt/mysql_data/
注意:
5.检查目录,并配置权限
mkdir /mnt/mysql_data
mkdir /var/log/mysql
mkdir /var/lib/mysql
touch /mnt/mysql_data/mysql.pid
touch /var/lib/mysql/mysql.sock
chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /var/log/mysql
chown -R mysql:mysql /mnt/mysql_data
chmod 777 /var/lib/mysql/mysql.sock
chmod 777 /mnt/mysql_data/mysql.pid
6复制启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
7.修改启动路径
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/mnt/mysql_data
8.增加环境变量 (最下面添加)
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
9.刷新配置文件
source /etc/profile
修改配置文件
vi /etc/my.cnf
[client]
port = 3306
default-character-set = utf8
socket = /var/lib/mysql/mysql.sock
[mysqld]
basedir = /usr/local/mysql
datadir = /mnt/mysql_data
socket = /var/lib/mysql/mysql.sock
log-error = /var/log/mysql/error.log
pid-file = /mnt/mysql_data/mysql.pid
max_connections = 300
character-set-server = utf8
default-storage-engine = INNODB
lower_case_table_names = 1
max_allowed_packet = 16M
user = mysql
tmpdir = /tmp
default_authentication_plugin = mysql_native_password
[mysql]
default-character-set = utf8
socket = /var/lib/mysql/mysql.sock
11.添加开启自启
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
netstat -anpt
13.修改root默认密码并授权远程访问:
在/etc/my.cnf 最后增加: skip-grant-tables = 1
重启MySQL: /etc/rc.d/init.d/mysqld restart
mysql -uroot -p
use mysql;
update user set host = '%', authentication_string = '' where user='root';
flush privileges;
select host, user, authentication_string, plugin from user;
删除/etc/my.cnf文件中的 skip-grant-tables = 1
重启MySQL: /etc/rc.d/init.d/mysqld restart
ALTER USER USER() IDENTIFIED BY 'Tmp123456';
暂时关闭防火墙测试远程连接:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
systemctl status iptables