MySQL5.7新特性之初始化
1. 把⼆进制安装包下载放在/opt ⽬录下并解压
2. 创建软连接,并添加运⾏环境
ln -s /usr/local/mysql /opt/mysql-5.7.18-linux-glibc2.5-x86_64
[root@M1 local]# ll | grep mysql
lrwxrwxrwx 1 root root 39 Jul 26 12:00 mysql -> /opt/mysql-5.7.18-linux-glibc2.5-x86_64
export PATH=$PATH:$HOME/bin:/usr/local/mysql/bin 加到环境变量
3. 创建mysql ⽤户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
4. 创建⽬录结构和赋权
mkdir /data/mysql/3306/ -p
cd data
mkdir {data,logs,tmp}
chown mysql:mysql -R /data
5.⽣产cnf 配置⽂件
6. 初始化
[root@M1 bin]# ./mysqld --initialize --datadir=/data/mysql/3306/data --user=mysql --basedir=/usr/local/mysql/
2017-07-26T08:24:03.273745Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --
explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-26T08:24:04.102255Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-26T08:24:04.243150Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-26T08:24:04.314543Z 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: c9102823-71db-11e7-ba5c-005056b643b3.
2017-07-26T08:24:04.321167Z 0 [Warning] Gtid table is not ready to be used. Table 'id_executed' cannot be opened.
2017-07-26T08:24:04.322012Z 1 [Note] A temporary password is generated for root@localhost: 2hpi85k*T-t=
我们可以看到root@localhost 被赋予随机⽣成的⼀个密码,这与以往的mysql版本不⼀样,另外mysql_install_db 这个⼯具也不再被推荐了, mysql_install_db is deprecated. Please consider switching to mysqld --initialize
另外,在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error ⽇志⽂件中(在5.6版本中是放在 ~/.mysql_secret ⽂件⾥,更加隐蔽,不熟悉的话可能会⽆所适从)
7.启动数据库
8. 使⽤刚刚⽣成的密码就可以正常登录了
[root@M1 bin]# mysql -uroot -p -S /data/mysql3306.sockmysql下载后的初次使用
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
9. 想要更加美观? 也是可以的
在~/.bash_profile 加上export MYSQL_PS1="\\u@\\h:\\p [\\d]>"
或者可以在[mysql] 添加
[mysql]
prompt=\\u@\\h:\\p [\\d]>
root@localhost:mysql3306.sock [(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
root@localhost:mysql3306.sock [(none)]>use sys
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
root@localhost:mysql3306.sock [sys]>
==========最后总结======
快速初始化脚本如下:
1. 把压缩⽂件放在/opt 下⾯
2. myf ⽂件的内容需要和以下⽂件⽬录匹配
#!/bin/sh
cd /opt
tar zxvf mysql*.
ln -s /usr/local/mysql /opt/mysql*linux-glibc2.5-x86_64
cat >> /etc/profile <<EOF
export MYSQL_PS1="\\u@\\h:\\p [\\d]>"
export PATH=\$PATH:/usr/local/mysql/bin
EOF
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mkdir /data/mysql/3306/ -p
cd /data/mysql/3306
mkdir {data,logs,tmp}
chown mysql:mysql -R /data

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。