在Linux中安装MySQL
1.编辑版本下载地址
vim /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
2.下载MySQL:
1)下载rpm包
wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
2.安装rpm
rpm -ivh mysql57-community-release-el6-7.noarch.rpm
3.yum 安装
yum install -y mysql-community-client mysql-community-server
yum install -y net-tools 安装依赖文件net-tools
将我发的mysql-community-server的rpm包发送到虚拟机。 mysql-community-server
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm 安装
4.启动服务
systemctl start mysqld
systemctl enable mysqld
5.查看临时密码 最后写是临时密码
cat /var/log/mysqld.log | grep “temporary password”
如果没有显示出密码,可以删除/var/lib/mysql,然后重新启动服务
注意:然后通过 mysql -u root -p 回车, 进入后将临时密码粘贴进去,回车就进去了。
6.修改密码
alter user ‘root’@‘localhost’ identified by ‘123456你自己得mysql密码’;
报错就执行下面两句 再次重新修改密码:
set global validate_password_policy=LOW;
set global validate_password_length=4;
7.打开远程连接
update mysql.user set host=’%’ where user=‘root’;
8.刷新授权
flush privileges;
9.重启服务
service mysqld restart