部署 MySQL:在服务器上部署 MySQL,使用二进制安装方式安装 MySQL
安装目录为/usr/local/mysql
数据库目录为:/usr/local/mysql/data
配置文件 /etc/my.cnf
socket 文件位置:/usr/local/mysql/data/mysql.sock
错误日志文件位置 /usr/local/mysql/data/mysql.log
pid-file 文件位置:/usr/local/mysql/data/mysql.pid
1,准备基础环境(centos7最小化安装+mysql5.7.30)
centos关闭selinux,不需要关闭
cd /usr/local/
tar zxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz mysql
2,添加用户和权限,不允许登录系统
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
3,编辑配置文件my.cnf
vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
#socket=/var/lib/mysql/mysql.sock
socket=/usr/local/mysql/data/mysql.sock
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
#skip_name_resolve = 1
port = 3306
[client]
port = 3306
socket=/usr/local/mysql/data/mysql.sock
(参数就不解释了,想知道自己查吧)
4,初始化数据库,创建pid文件
cd /usr/local/mysql/bin
./mysqld --initialize --user=root --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cd /data/
vim mysql.pid
3306
chown -R mysql:mysq /usr/local/mysql/data
cd ../support-files/
./msyql.server start
5,进入数据库,修改密码
先查看初始密码
cat ../data/mysql.log | grep password
cd ../bin
./mysql -u root -p
输入密码,修改root密码
完成!