当前位置:Gxlcms > 数据库问题 > mysql5.7:安装教程

mysql5.7:安装教程

时间:2021-07-01 10:21:17 帮助过:22人阅读

切换目录 cd /usr/local #解压下载的安装包 tar -zxvf /software/mysql/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz #重命名 mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql #建立数据存储目录 mkdir data #建立用户组 groupadd mysql #建立用户,并禁止用户登录 useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql #改变文件归属 chown -R mysql.mysql /usr/local/mysql/ #初始化系统数据库,记住不能用./bin/mysql_install_db,已经过期了 ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

初始化后,会打印日志,如下 ,注意看最后输出,红色标记部分,这个就是root的临时密码

  1. <span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.048923Z <span style="color: #800080">0</span> [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please <span style="color: #0000ff">use</span> --explicit_defaults_for_timestamp server option (see doc umentation <span style="color: #0000ff">for</span><span style="color: #000000"> more details).
  2. </span><span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.228535Z <span style="color: #800080">0</span> [Warning] InnoDB: New log files created, LSN=<span style="color: #800080">45790</span>
  3. <span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.251370Z <span style="color: #800080">0</span><span style="color: #000000"> [Warning] InnoDB: Creating foreign key constraint system tables.
  4. </span><span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.305856Z <span style="color: #800080">0</span> [Warning] No existing UUID has been found, so we a ssume that this is the first <span style="color: #0000ff">time</span> that this server has been started. Generating a new UUID: 968b7130-f756-11e7-<span style="color: #800080">8704</span>-<span style="color: #000000">000c29009e57.
  5. </span><span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.306388Z <span style="color: #800080">0</span> [Warning] Gtid <span style="color: #0000ff">table</span> is <span style="color: #0000ff">not</span> ready to be used. Tabl e <span style="color: #800000">‘</span><span style="color: #800000">mysql.gtid_executed</span><span style="color: #800000">‘</span><span style="color: #000000"> cannot be opened.
  6. </span><span style="color: #800080">2018</span>-<span style="color: #800080">01</span>-12T05:<span style="color: #800080">08</span>:<span style="color: #800080">12</span>.307188Z <span style="color: #800080">1</span> [Note] A temporary password is generated <span style="color: #0000ff">for</span> root@localhost: <font color="#ff0000"><font size="4">LwchxXdoO5*8</font></font>

配置数据库:

  1. vi /etc/<span style="color: #0000ff">my</span>.cnf

my.cnf内容:

  1. <span style="font-weight: bold; color: #800000">[</span><span style="color: #800000">mysqld</span><span style="font-weight: bold; color: #800000">]</span><span style="color: #000000">
  2. #目录设置
  3. basedir</span>=<span style="color: #000000">/usr/local/mysql
  4. datadir</span>=<span style="color: #000000">/usr/local/mysql/data
  5. port</span>=3306<span style="color: #000000">
  6. #服务ID
  7. socket</span>=<span style="color: #000000">/tmp/mysql.sock
  8. #数据库表名大小写不敏感
  9. lower_case_table_names</span>=1<span style="color: #000000">
  10. #设置字符集,防止中文乱码
  11. init_connect</span>=‘SET collation_connection =<span style="color: #000000"> utf8_general_ci‘
  12. init_connect</span>=<span style="color: #000000">‘SET NAMES utf8‘
  13. character-set-server</span>=<span style="color: #000000">utf8
  14. collation-server</span>=<span style="color: #000000">utf8_general_ci
  15. skip-character-set-client-handshake
  16. </span><span style="font-weight: bold; color: #800000">[</span><span style="color: #800000">client</span><span style="font-weight: bold; color: #800000">]</span><span style="color: #000000">
  17. default-character-set</span>=<span style="color: #000000">utf8
  18. </span><span style="font-weight: bold; color: #800000">[</span><span style="color: #800000">mysql</span><span style="font-weight: bold; color: #800000">]</span><span style="color: #000000">
  19. default-character-set</span>=utf8

安装成服务:

  1. cp -a ./support-files/mysql.server /etc/init.d/mysqld

启动服务

  1. service mysqld start

登录到mysql

  1. ./bin/mysql -u root -<span style="color: #000000">p
  2. Enter password</span>:<span style="color: #000000">
  3. Welcome to the MySQL monitor</span>. Commands end with ; or \g.<span style="color: #000000">
  4. Your MySQL connection id is </span><span style="color: #800000">3</span><span style="color: #000000">
  5. Server version</span>: <span style="color: #800000">5.7</span>.<span style="color: #800000">20</span><span style="color: #000000">
  6. Copyright (c) </span><span style="color: #800000">2000</span>, <span style="color: #800000">2017</span>, Oracle and/or its affiliates. All rights reserved.<span style="color: #000000">
  7. Oracle is a registered trademark of Oracle Corporation and</span>/<span style="color: #000000">or its
  8. affiliates</span>.<span style="color: #000000"> Other names may be trademarks of their respective
  9. owners</span>.<span style="color: #000000">
  10. Type </span><span style="font-weight: bold; color: #000000">‘</span><span style="font-weight: bold; color: #000000">help;</span><span style="font-weight: bold; color: #000000">‘</span> or <span style="font-weight: bold; color: #000000">‘</span><span style="font-weight: bold; color: #000000">\h</span><span style="font-weight: bold; color: #000000">‘</span> <span style="color: #0000ff">for</span> help. Type <span style="font-weight: bold; color: #000000">‘</span><span style="font-weight: bold; color: #000000">\c</span><span style="font-weight: bold; color: #000000">‘</span> to clear the current input statement.<span style="color: #000000">
  11. mysql</span>> grant all privileges on *.* to root@<span style="font-weight: bold; color: #000000">"</span><span style="font-weight: bold; color: #000000">%</span><span style="font-weight: bold; color: #000000">"</span> identified by <span style="font-weight: bold; color: #000000">"</span><span style="font-weight: bold; color: #000000">2018dlj123!@#0112</span><span style="font-weight: bold; color: #000000">"</span><span style="color: #000000"> with grant option;
  12. ERROR </span><span style="color: #800000">1820</span> (HY000): <font color="#ff0000" size="3">You must reset your password using ALTER USER statement before executing this statement.</font>

一开始想做授权,结果发现报错,原因是必须要修改初始密码。

修改初始密码:

  1. mysql> ALTER USER USER() IDENTIFIED BY <span style="font-weight: bold; color: #000000">‘</span><span style="font-weight: bold; color: #000000">test123456</span><span style="font-weight: bold; color: #000000">‘</span>;
  1. Query OK, 0 rows affected (0.00 sec)

mysql> use mysql
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
mysql> grant all privileges on *.* to root@"%" identified by "test123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

至此安装完毕!

mysql5.7:安装教程

标签:hang   cal   statement   建立   create   error   tin   红色   cccccc   

人气教程排行