暂无说说

centos7安装mysql

linux jiajun 11个月前 (12-02) 162次浏览 0个评论 扫描二维码

1、mysql 官方地址

mysql 的 yum 源地址:https://dev.mysql.com/downloads/repo/yum/
mysql 离线包下载地址:https://downloads.mysql.com/archives/

2、下载 MySQL 的 yum 源安装包

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
sudo yum install -y mysql80-community-release-el7-1.noarch.rpm

3、查看 mysql 源

yum repolist all | grep mysql

结果:

mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     74
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community/x86_64       MySQL Tools Community         enabled:     74
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
mysql57-community/x86_64           MySQL 5.7 Community Server    disabled
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    enabled:     49
mysql80-community-source           MySQL 8.0 Community Server -  disabled

默认开启 MySQL 8.0,如果要改成 MySQL 5.7,可以使用以下命令:

sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community

4、这里安装 mysql57

sudo yum -y install yum-utils
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
sudo yum install mysql-community-server

5、启动 mysql

sudo systemctl start  mysqld.service

查看 mysql 运行状况

systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-12-01 23:50:41 EST; 1min 39s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5146 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5056 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5148 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─5148 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Dec 01 23:50:30 hadoop systemd[1]: Starting MySQL Server...
Dec 01 23:50:41 hadoop systemd[1]: Started MySQL Server.

6、初始化数据库密码

查看一下初始密码

grep "password" /var/log/mysqld.log

登录

mysql -uroot -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '****************';

mysql 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:
大小写字母、数字和特殊符号,并且长度不能少于 8 位。否则会提示 ERROR 1819 (HY000): 
Your password does not satisfy the current policy requirements 错误

7、数据库授权

数据库没有授权,只支持 localhost 本地访问

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

说明:
//远程连接数据库的时候需要输入用户名和密码
用户名:root
密码:Aa1234567?     //密码要求见第 6 步说明
指点 ip:%代表所有 Ip,此处也可以输入 Ip 来指定 Ip


输入后刷新权限

FLUSH PRIVILEGES;

也可以通过修改表来实现远程:   

mysql -u root -p

mysql> use mysql; 
mysql> update user set host = '%' where user = 'root'; 
mysql> select host, user from user;

8、设置自动启动

sudo systemctl enable mysqld
sudo systemctl daemon-reload

 

喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址