半寸时光丶关注
2021.03.28 16:02:38字数 195阅读 110
安装mysql
获取官方下载地址 https://dev.mysql.com/downloads/repo/yum/
下载mysql安装包 :wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
将下载好的安装包挂载到本地:yum localinstall mysql80-community-release-el8-1.noarch.rpm
查看是否挂载成功:yum repolist enabled | grep "mysql.*-community.*"
禁用centos8.0自带的mysql模块:yum module disable mysql
安装mysql:yum install mysql-community-server
启动mysql服务service mysqld start
查看mysql服务启动状态service mysqld status
mysql服务相关命令
启动服务:service mysqld start
停止服务:service mysqld stop
重启服务:service mysqld restart
查看服务状态:service mysqld status
设置mysql开机自启:
systemctl enable mysqld
systemctl daemon-reload
修改mysql密码并开放远程连接
查看mysql安装时生成的随机密码:grep 'temporary password' /var/log/mysqld.log
登录mysql
mysql -uroot -p'刚获取到的随机密码'
安装mysql后第一次登录需要修改密码
ALTER USER 'root' @'localhost' IDENTIFIED BY '你的密码';
开放mysql远程访问
创建权限记录:
CREATE user 'root'@'%' IDENTIFIED BY 'root123';
授权:
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' WITH GRANT OPTION;
修改密码过期策略:
ALTER USER 'root' @'localhost' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;
重新修改密码:
ALTER USER 'root' @'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
刷新权限:
FLUSH PRIVILEGES;