mysql下載地址:https://downloads.mysql.com/archives/community/
1.下載 解壓
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar xzf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
2.移動mysql到對應(yīng)目錄
mv /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
3.創(chuàng)建用戶和組并賦權(quán)限
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql mysql
4.配置mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
vim /etc/my.cnf
#錄入一下內(nèi)容
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/server/mysql
socket=/tmp/mysql.sock
log-error=/data/server/mysql/mysql.err
pid-file=/data/server/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
初始化數(shù)據(jù)庫
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/server/mysql/ --user=mysql --initialize
5.啟動mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
6.修改mysql密碼 創(chuàng)建遠程賬戶
/usr/local/mysql/bin/mysql -u root -p
SET PASSWORD=PASSWORD('root');
flush privileges;
use mysql;
create user 'test001' identified by '123456';
grant all privileges on *.* to 'test001'@'%' identified by '123456' with grant option;
flush privileges;
7.修改mysql為全局命令
vim /etc/profile
末尾加入
export PATH=$PATH:/data/server/go/bin
export GOPATH=/data/web/go/
export GOROOT=/data/server/go
export PATH=$PATH:/data/server/php/bin
export PATH=$PATH:/usr/local/mysql/bin
然后source /etc/profile
期間可能報兩個錯誤 一個
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
yum install -y numactl 解決
(dnf upgrade libmodulemd解決centos8 yum報錯問題)
error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
yum install -y libncurses* 解決