创建mysql组及用户:
groupadd mysql useradd -r -g mysql -s /bin/false mysql
建立相关目录:
mkdir -p /data/mysql/mysql3306/{data,logs,tmp} chown -R mysql.mysql /data/mysql
初始化MySQL:
ln -s /opt/mysql-5.7.21-linux-glibc2.12-x86_64/ /usr/local/mysql chown -R mysql.mysql /opt/mysql-5.7.20-linux-glibc2.12-x86_64 chown -R mysql.mysql /usr/local/mysql /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
查找root密码:
cat /data/mysql/mysql3306/data/error.log |grep password
启动MySQL:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
登陆MySQL:
mysql -S /tmp/mysql3306.sock -p
修改root密码,删除危险账户:
alter user user() identified by ‘password‘; delete from mysql.user where user!=‘root‘ or host!=‘localhost‘; flush privileges;
关闭MySQL:
mysqladmin -S /tmp/mysql3306.sock -p shutdown
添加MySQL PATH:
vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql/bin
多实例:
建立3307所需目录:
mkdir -p /data/mysql/mysql3307/{data,logs,tmp}
初始化3307:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307cnf --initialize
查找3307 root密码:
cat /data/mysql/mysql3307/data/error.log |grep password
启动3307:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf &
登陆3307:
mysql -S /tmp/mysql3307.sock -p
关闭3307:
mysqladmin -S /tmp/mysql3307.sock -p shutdown