美文网首页
centos7中安装mysql

centos7中安装mysql

作者: suchcl | 来源:发表于2019-01-28 19:48 被阅读0次

环境:centos7.3
mysql:5.7

  1. 数据库安装
# 下载mysql5.7源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
yum localinstall -y mysql57-community-release-el7-8.noarch.rpm
# 安装mysql服务
yum install mysql-community-server
  1. mysql服务管理
# 启动mysql数据库
systemctl start mysqld.service
# 设置mysql的开机启动
systemctl enable mysqld.service
# 重启mysql服务
systemctl restart mysqld.service
# 查看mysql的服务状态
systemctl status mysqld.service
  1. 初始密码
    mysql安装完成后是有初始密码的,不过这个密码是随机的,用户名是默认的root,这个密码在mysql的日志文件中。
    centos7.3安装完mysql后log文件的默认地址在:
/var/log/mysqld.log

mysql 的配置文件默认在:

/etc/my.cnf

可以从mysql的配置文件下查看到一些有用信息:

vim 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

# 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

可以从配置文件中找到数据文件的存放目录:datadir=/var/lib/mysql
日志文件地址:log-error=/var/log/mysqld.log
pid文件:pid-file=/var/run/mysqld/mysqld.pid
前面一大堆的铺垫,就为了要说mysql的初始密码存放在了log文件中。

vim /var/log/mysqld.log

……
2019-01-28T09:56:33.184635Z 1 [Note] A temporary password is generated for root@localhost: T_h>H&giP5OA
……

找到大致内容是这样的一行代码,最后的关键词是:password is generated for root@localhost: T_h>H&giP5OA,这最后的内容就是密码了。结下来就是改了。

# 通过默认的用户名、密码登录数据库 
mysql -u root -p
# 输入密码
T_h>H&giP5OA #密码输入时不显示的,不要因为没有看见而以为没有输入成功

# 改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

注意新密码的策略:最好是密码复杂度高一点,有大小写、数字和特殊字符的混编。好像从高版本开始,这是一个必须的策略,但没有查证具体是从哪个版本开始的。改好后就可以使用新密码登录和使用数据库了。

相关文章

网友评论

      本文标题:centos7中安装mysql

      本文链接:https://www.haomeiwen.com/subject/znrzjqtx.html