linux下安装mysql 发表于 2019-07-24 | 分类于 linux 字数统计: 470 1.安装 1234567891011121314151617181920#获取安装用的Yum Repositorywget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmyum -y install mysql57-community-release-el7-10.noarch.rpm#安装MySQL服务yum -y install mysql-community-server#查看版本mysql -v#启动mysqlsystemctl start mysqld.service#找回初始密码并登录 jWTAeq-DF9tJgrep 'temporary password' /var/log/mysqld.logmysql -uroot -p#注意;找不到初始密码及其他情况参考下文"修改密码"#使用初始密码登录后需要先修改一次密码后才能操作ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';#为避免Repository每次yum操作都会自动更新yum -y remove mysql57-community-release-el7-10.noarch 2.修改密码 1234567891011121314151617#1.找回密码grep 'temporary password' /var/log/mysqld.log#2.强制修改密码systemctl stop mysqld #停止服务systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" #跳过密码systemctl start mysqld #启动服务mysql -u root #登录UPDATE mysql.user SET authentication_string = PASSWORD('新密码') WHERE User = 'root' AND Host = 'localhost'; #设置新密码FLUSH PRIVILEGES; #刷新权限quit #退出#3.用操作系统账号修改密码mysql -uroot -p #使用centos账号密码登录UPDATE mysql.user SET authentication_string = PASSWORD('新密码') WHERE User = 'root' AND Host = 'localhost'; #设置新密码FLUSH PRIVILEGES; #刷新权限quit #退出 3.修改远程连接权限 1234567891011#选择mysqluse mysql;#授权远程连接GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'YYBrhr_2018' WITH GRANT OPTION;#注意:如果navicat远程连接报1521错误GRANT ALL ON *.* TO 'root'@'%'; #远程连接授权ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更改加密规则ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #更改密码FLUSH PRIVILEGES; #刷新权限 注意,这一步需要小心,在自己的服务器或者内网的服务器就算了,如果是在外网的生产服务器上,务必先咨询同事。