Linux 安装Mysql 8.0.*
创建目录
cd /usr/local/
mkdir mysql
cd /mysql
下载压缩包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
解压&重命名
tar -xvf 压缩包名称(按 table 键自动联想)
mv 文件夹名称(按 table 键自动联想) mysql-8.0
cd mysql-8.0
创建用户组
groupadd mysql (创建过的可以跳过)
useradd -g mysql mysql (创建过的可以跳过)
授权
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
安装(安装后保存好临时密码 )
cd /usr/local/mysql/mysql-8.0/bin
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql/mysql-8.0/data/ --initialize
编辑 my.cnf
vi /etc/my.cnf
完整内容如下:
[mysqld]
basedir=/usr/local/mysql/mysql-8.0/
datadir=/usr/local/mysql/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
# 不需要日志可以注释下列三行
#[mysqld_safe]
#log-error=/usr/local/mysql/error.log
#pid-file=/usr/local/mysql/id.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
创建MYSQL服务
cp -a ./support-files/mysql.server /etc/init.d/mysql
不知道这个文件夹有啥用反正创建就对了
mkdir /etc/my.cnf.d/ (my.cnf 中使用了该文件夹 如果有了可以忽略此步)
启动服务
service mysql start
登陆前创建环境变量(也不知道是不是环境变量。。。反正我登陆的时候报错)
ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
vim ~/.bash_profile
在文件末尾处写入
export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin
授权
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
下面的就不解释了,逐行运行就好了
mysql mysql -uroot -p生成的随机密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';(正式环境请设置复杂密码)
flush privileges;
use mysql;
update user set host='%' where user='root';
flush privileges;
开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
完毕
|