阿里云 CentOS 7.3下rpm安装MySQL 5.7.18(2)

a 数据库目录
/var/lib/mysql/
b 配置文件
/usr/share/mysql(mysql.server命令及配置文件)
c 相关命令
/usr/bin(mysqladmin mysqldump等命令)
d 启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)

e /etc/my.conf

5、 数据库初始化

为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你的linux系统是以 root 身份运行 mysql 服务,需要执行下面的命令初始化

[root@linuxidc mysql]# mysqld --initialize --user=mysql

如果是以 mysql 身份登录运行,则可以去掉 --user 选项。

另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码,

而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。

这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里,红色区域的就是自动生成的密码

[root@linuxidc mysql]# cat /var/log/mysqld.log 2017-06-05T14:30:52.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-06-05T14:30:55.590590Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-06-05T14:30:56.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-06-05T14:30:56.109868Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 960c533e-49fb-11e7-91f2-00163e089fd2. 2017-06-05T14:30:56.116186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-06-05T14:30:56.116777Z 1 [Note] A temporary password is generated for root@localhost: :Wu?2QQutQwj

现在启动mysql数据库systemctl start mysqld.service(Centos7特有的启动方式)

[root@linuxidc mysql]# systemctl start mysqld.service

可以使用下面两个命令对mysql进行停止,启动和重启:

启动:

使用 service 启动:service mysqld start 使用 mysqld 脚本启动:/etc/inint.d/mysqld start 使用 safe_mysqld 启动:safe_mysqld&

停止:

使用 service 启动:service mysqld stop 使用 mysqld 脚本启动:/etc/inint.d/mysqld stop mysqladmin shutdown

重启:

使用 service 启动:service mysqld restart 使用 mysqld 脚本启动:/etc/inint.d/mysqld restart

连接数据库

[root@linuxidc mysql]# mysql -u root -p
Enter password:

密码输入:  :Wu?2QQutQwj

修改密码:

set password = password('你的密码');

设置远程访问

grant all privileges on *.* to 'root' @'%' identified by '123456'; flush privileges;

设置mysql开机启动

加入到系统服务: chkconfig --add mysql 自动启动: chkconfig mysql on 查询列表: chkconfig 说明:都没关闭(off)时是没有自动启动。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/04887f8626a176e54c2cbd4d1bc2197c.html