MySQL 介绍和安装(二)—老男孩MySQL培训

    /    2019-06-18

方法二 :
初始化数据,初始化管理员的密码为空
\rm -rf  /data/mysql/*
[root@db01 ~]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2019-04-18T03:37:43.1460180 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:37:43.8921320 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:37:43.9704120 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:37:44.0294900 [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: 5378f3b3-618b-11e9-9164-000c294234c8.
2019-04-18T03:37:44.0414690 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:37:44.0423481 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@db01 ~]
[root@db01 ~]# cd /data/mysql/
[root@db01 mysql]# ll
total 110628
-rw-r----- 1 mysql mysql       56 Apr 18 11:37 auto.cnf
-rw-r----- 1 mysql mysql      419 Apr 18 11:37 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Apr 18 11:37 ibdata1
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 Apr 18 11:37 mysql
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 performance_schema
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 sys
[root@db01 mysql]

注释:5.6初始化的区别

/application/mysql/scripts/mysql_install_db  --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql

5.6 书写默认配置文件

vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>

5.7 配置启动脚本:

[root@db01 mysql]# cd /app/mysql/support-files
[root@db01 support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/db01.err'.
 SUCCESS! 
cp mysql.server    /etc/init.d/mysqld

5.8 使用systemd管理mysql

vim /etc/systemd/system/mysqld.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

注意:将原来模式启动mysqld先关闭,然后再用systemd管理。

systemctl  start/stop/restart/status   mysqld

6. 安装后的简单管理

[root@db01 ~]# mysqladmin -uroot -p password 123
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
5.6版本:
select user,password,host from mysql.user;
5.7 中用户基本信息
select user,authentication_string,host from mysql.use

小结:
1.版本 (主流版本的GA时间了解一下)

5.6 5.7 
5.6.38   5.7.20 
20170913 
(1) 初始化方式变了
mysql_install_db   
mysqld  --initialize-insecure
(2) 用户安全
12位
180
4种复杂度
(3)密码字段
authentication_strings

2.安装方法:

二进制
源码
yum 

3.建库(初始化数据库)

mysqld --intialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql 

4.简易的配制文件/etc/my.cnf

user 
basedir
datadir 
server_id
port
socket 
  1. 管理员密码

mysqladmin -uroot -p password xx


(0)

分享至