系统环境
centos
使用yum 安装方式, 此方式会自动配置数据目录及root用户初始密码。
安装步骤
配置yum 仓库
可以下载地址 https://dev.mysql.com/downloads/repo/yum/
curl -O https://repo.mysql.com//mysql80-community-release-el6-3.noarch.rpm
下载后,使用如下命令,更新yum 的仓库地址
shell> sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm
查看可使用的mysql 版本
shell> yum repolist all | grep mysql ... mysql57-community MySQL 5.7 Community Server disabled mysql57-community-source MySQL 5.7 Community Server - S disabled mysql80-community MySQL 8.0 Community Server enabled: 113 mysql80-community-source MySQL 8.0 Community Server - S disabled
enable 的时当前激活的版本,可以通过命令指定需要安装的版本
shell> sudo yum-config-manager --disable mysql80-community shell> sudo yum-config-manager --enable mysql57-community
也可以通过手动编辑配置文件的方式来修改
修改 /etc/yum.repos.d/mysql-community.repo 文件,使用enabled=0 来禁用,enabled=1启用
[mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
验证参考配置是否正确
shell> yum repolist enabled | grep mysql [root@localhost local]# yum repolist enabled|grep mysql mysql-connectors-community MySQL Connectors Community 102 mysql-tools-community MySQL Tools Community 81 mysql57-community MySQL 5.7 Community Server
执行安装
会安装mysql-community-server,mysql-community-client,mysql-community-common,mysql-community-libs。
shell> sudo yum install mysql-community-server
启动mysql 服务
shell> sudo service mysqld start Starting mysqld:[ OK ] 另一种启动方法:bin/mysqld_safe --user=mysql & 使用非root用户启动
设置密码
查看临时密码, 如下面的密码为 "ICQdsjd!K94)"
sudo grep 'temporary password' /var/log/mysqld.log 1 [Note] A temporary password is generated for root@localhost: ICQdsjd!K94)
更改密码
shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
开启防火墙,允许外部访问
// 指定网段
sudo firewall-cmd --zone=public --permanent --add-rich-rule 'rule family="ipv4" source address=192.168.43.0/24 port protocol="tcp" port="3306" accept' // 添加规则 firewall-cmd --zone=public --add-port=3306/tcp --permanent
// 加载防火墙信息 firewall-cmd --reload