本人尝试过使用源码安装方式,那叫一个头疼,各种问题,于是采用yum方式安装,没想到如此简单:
此服务器是刚买的,所以以前没有安装过mysql,如果以前安装过mysql的,好像要卸载干净再安装(其实我也不懂~)。
开始吧:
1、配置yum源
#下载mysql源安装包(默认5.7最新版本)
[[email protected] ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm#安装mysql源
[[email protected] ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
检测yum源是否安装成功
[[email protected] ~]# yum repolist enabled | grep "mysql.*-community.*"
如上图所示即安装成功
2、安装MySQL
[[email protected] ~]# yum -y install mysql-server
等一会就安装好了
默认配置文件路径:
/etc/my.cnf #配置文件
/var/log/var/log/mysqld.log #日志文件
/usr/lib/systemd/system/mysqld.service #服务启动脚本
/var/run/mysqld/mysqld.pid #socket文件
3、配置 my.cnf
[[email protected] ~]# vim /etc/my.cnf
#For advice on how to change settings please see#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]#
#Remove leading # and set to the amount of RAM for the most important data#cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.#innodb_buffer_pool_size = 128M#
#Remove leading # to turn on a very important data integrity option: logging#changes to the binary log between backups.#log_bin#
#Remove leading # to set options mainly useful for reporting servers.#The server defaults are faster for transactions and fast SELECTs.#Adjust sizes as needed, experiment to find the optimal values.#join_buffer_size = 128M#sort_buffer_size = 2M#read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id= 1expire_logs_days= 3
#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
my.cnf
4、启动mysql服务
[[email protected] ~]# service mysqld restart
5、查看密码(因为安装好后,第一次登录密码为随机密码)
[[email protected] ~]# grep "password" /var/log/mysqld.log
输入 mysql -u root -p 回车,再输入上面的随机密码,回车,即可登录MySQL。
6、重置密码
注意:
ip处填localhost,不要填%
密码必须包含数字、字母、符号(为了安全)
mysql> alter user "root"@"localhost" identified by "新密码";
记得要刷新权限
mysql> flush privileges;
exit退出MySQL,再次登录就可以用设置好的密码了。
1