centos安装mysql7

删除mysql相关的依赖

查询已安装的rpm包

rpm -qa | grep mysql

若查询有结果,需删除

rpm -e --nodeps mysql-libs-xxx

删除相关mysql目录并删除

查询mysql目录

find / -name mysql 

查询mysql命令

whereis mysql

下载mysql二进制包

进入/user/local/src/

cd /uer/local/src/

下载mysql

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

解压

tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

构建mysql目录

创建mysql BaseDir

mkdir -p /usr/local/mysql/data

移动mysql文件至BaseDir

mv mysql-5.7.37-linux-glibc2.12-x86_64/* /usr/local/mysql/

初始化mysql用户

创建mysql用户、创建用户组并将mysql加入mysql用户组

groupadd mysql
useradd -r -g mysql mysql

改变mysql目录所属组和所属用户

chown -R mysql:mysql /usr/local/mysql

赋予mysql用户及用户组对mysql目录对最大访问权限

chmod +775 /usr/local/mysql

安装mysql

初始化mysql,需要保存以下命令输出后的最后一段的临时密码,至关重要!

/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

启动mysql

/usr/local/mysql/support-files/mysql.server start

添加软连接,并重启mysql服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart

登陆mysql

mysql -u root -p
输入刚刚的保存的临时密码

输入以下sql语句,修改root用户密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;

远程访问

use mysql;
update user set user.Host='%' where user.User='root';

允许root用户在任何地方进行远程登录,并具有所有库任何操作权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

刷新权限

FLUSH PRIVILEGES;

设置mysql系统服务

复制mysql服务并赋予执行权限
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
添加mysql系统服务
chkconfig --add mysqld

你可能感兴趣的:(centos安装mysql7)