在CentOS7中使用yum方式安装mysql是非常方便的,但是yum服务器缺省都在国外,mysql安装包下载速度非常慢,只有数k每秒,全部下载要很长时间,即使源改为阿里云,也非常慢,因为mysql自身的源还在国外。
现在使用下载rpm包的安装方式来进行mysql的安装,顺利的话一二十分钟搞定。
1、Centos7下自带mariadb,如要安装mysql的话,需先卸除mariadb数据库。
rpm -qa mariadb*
rpm -e ***
注:***为第一条查询出来的数据
2、 准备好下载安装包。下载地址:
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.28-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.28-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-devel-5.7.28-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.28-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.28-1.el7.x86_64.rpm
下载方式用迅雷最快,速度可达6-8MBps。wget方式因为是单线程,速度在40-50kBps。
3、 使用SSH带的SFTP方式上传至目标linux系统中,SecureCRT中有上传SFTP方式。
4、 运行rpm安装mysql,注意有先后顺序。
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
5、 启动mysql
systemctl start mysqld
查看mysql进程是否正常
systemctl status mysqld
6、 找到系统生成的mysql初始密码
grep ‘temporary password’ /var/log/mysqld.log
[Note] A temporary password is
generated for root@localhost: kTekZg>tn4dj
7、 登录mysql
mysql -uroot -p
输入刚才找到的密码kTekZg>tn4dj
8、 更改密码
ALTER USER ‘root’@‘localhost’
IDENTIFIED BY ‘Qwert***’;
下面这种方式也可以修改密码:
set password=password(‘Qwert***’) ;
9、 查看状态
mysql>show databases; 正常表示mysql安装成功。