暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL5.7.15安装、登录、远程登录

大数据真有意思 2017-08-13
344

创建mysql用户和组

  1. # groupadd mysql

  2. # useradd -r -g mysql -s bin/false mysql

解压mysql-5.7.15-linux-glibc2.5-x86_64.tar到/usr/local下面,执行如下命令

  1. # cd /usr/local

  2. # ln -s mysql-5.7.15-linux-glibc2.5-x86_64 mysql

  3. # cd mysql

  4. # mkdir mysql-files

  5. # chmod 750 mysql-files

  6. # # chown -R mysql .

  7. # chgrp -R mysql .

  8. # bin/mysqld --initialize --user=mysql

  9. 2016-09-10T14:19:07.373035Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

  10. 2016-09-10T14:19:10.479748Z 0 [Warning] InnoDB: New log files created, LSN=45790

  11. 2016-09-10T14:19:10.823291Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

  12. 2016-09-10T14:19:10.995510Z 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: 8b0f6916-7761-11e6-bbac-00163e001537.

  13. 2016-09-10T14:19:11.025351Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

  14. 2016-09-10T14:19:11.029706Z 1 [Note] A temporary password is generated for root@localhost: S?gFkFr;5)TZ

  15. # bin/mysql_ssl_rsa_setup

  16. Generating a 2048 bit RSA private key

  17. ............................................+++

  18. .................................................+++

  19. writing new private key to 'ca-key.pem'

  20. -----

  21. Generating a 2048 bit RSA private key

  22. ....................................................................................................................................+++

  23. ...+++

  24. writing new private key to 'server-key.pem'

  25. -----

  26. Generating a 2048 bit RSA private key

  27. .....+++

  28. ...................+++

  29. writing new private key to 'client-key.pem'

  30. -----

  31. # chown -R root .

  32. # chown -R mysql data mysql-files

  33. # bin/mysqld_safe --user=mysql &

  34. [1] 5524

  35. # cp support-files/mysql.server /etc/init.d/mysql.server

查看服务进程

  1. # ps -ef|grep mysql

  2. root      5524  4768  0 22:21 pts/2    00:00:00 /bin/sh bin/mysqld_safe --user=mysql

  3. mysql     5610  5524  0 22:21 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/xxxx.err --pid-file=/usr/local/mysql/data/xxxx.pid

  4. root      5639  4768  0 22:22 pts/2    00:00:00 grep --color=auto mysql

停止mysql、启动mysql、重启mysql

  1. # /etc/init.d/mysql.server stop

  2. Shutting down MySQL..2016-09-10T14:26:53.055608Z mysqld_safe mysqld from pid file /usr/local/mysql/data/xxxx.pid ended

  3.                                                            [  确定  ]

  4. [1]+  完成                  bin/mysqld_safe --user=mysql

  5. # ps -ef|grep mysql

  6. root      5668  4768  0 22:27 pts/2    00:00:00 grep --color=auto mysql

  7. # /etc/init.d/mysql.server start

  8. Starting MySQL.  

  9. # /etc/init.d/mysql.server restart

  10. Shutting down MySQL..                                      [  确定  ]

  11. Starting MySQL.                                            [  确定  ]

客户端连接mysql服务,初始的随机密码位置在root目录下面

  1. # vi /root/.mysql_secret

如果使用刚刚的密码登录失败,则停止mysql,并跳过验证登录

  1. # cd /usr/local/mysql

  2. # ./bin/mysqld_safe --skip-grant-tables &

登录,查看user表结构和初始数据

  1. # /usr/local/mysql/bin/mysql

  2. Welcome to the MySQL monitor.  Commands end with ; or \g.

  3. Your MySQL connection id is 2

  4. Server version: 5.7.15 MySQL Community Server (GPL)


  5. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


  6. Oracle is a registered trademark of Oracle Corporation and/or its

  7. affiliates. Other names may be trademarks of their respective

  8. owners.


  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


  10. mysql> use mysql;

  11. Reading table information for completion of table and column names

  12. You can turn off this feature to get a quicker startup with -A


  13. Database changed

  14. mysql> desc user;

  15. +------------------------+-----------------------------------+------+-----+-----------------------+-------+

  16. | Field                  | Type                              | Null | Key | Default               | Extra |

  17. +------------------------+-----------------------------------+------+-----+-----------------------+-------+

  18. | Host                   | char(60)                          | NO   | PRI |                       |       |

  19. | User                   | char(32)                          | NO   | PRI |                       |       |

  20. | Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  21. | Insert_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  22. | Update_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  23. | Delete_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  24. | Create_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  25. | Drop_priv              | enum('N','Y')                     | NO   |     | N                     |       |

  26. | Reload_priv            | enum('N','Y')                     | NO   |     | N                     |       |

  27. | Shutdown_priv          | enum('N','Y')                     | NO   |     | N                     |       |

  28. | Process_priv           | enum('N','Y')                     | NO   |     | N                     |       |

  29. | File_priv              | enum('N','Y')                     | NO   |     | N                     |       |

  30. | Grant_priv             | enum('N','Y')                     | NO   |     | N                     |       |

  31. | References_priv        | enum('N','Y')                     | NO   |     | N                     |       |

  32. | Index_priv             | enum('N','Y')                     | NO   |     | N                     |       |

  33. | Alter_priv             | enum('N','Y')                     | NO   |     | N                     |       |

  34. | Show_db_priv           | enum('N','Y')                     | NO   |     | N                     |       |

  35. | Super_priv             | enum('N','Y')                     | NO   |     | N                     |       |

  36. | Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N                     |       |

  37. | Lock_tables_priv       | enum('N','Y')                     | NO   |     | N                     |       |

  38. | Execute_priv           | enum('N','Y')                     | NO   |     | N                     |       |

  39. | Repl_slave_priv        | enum('N','Y')                     | NO   |     | N                     |       |

  40. | Repl_client_priv       | enum('N','Y')                     | NO   |     | N                     |       |

  41. | Create_view_priv       | enum('N','Y')                     | NO   |     | N                     |       |

  42. | Show_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |

  43. | Create_routine_priv    | enum('N','Y')                     | NO   |     | N                     |       |

  44. | Alter_routine_priv     | enum('N','Y')                     | NO   |     | N                     |       |

  45. | Create_user_priv       | enum('N','Y')                     | NO   |     | N                     |       |

  46. | Event_priv             | enum('N','Y')                     | NO   |     | N                     |       |

  47. | Trigger_priv           | enum('N','Y')                     | NO   |     | N                     |       |

  48. | Create_tablespace_priv | enum('N','Y')                     | NO   |     | N                     |       |

  49. | ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |

  50. | ssl_cipher             | blob                              | NO   |     | NULL                  |       |

  51. | x509_issuer            | blob                              | NO   |     | NULL                  |       |

  52. | x509_subject           | blob                              | NO   |     | NULL                  |       |

  53. | max_questions          | int(11) unsigned                  | NO   |     | 0                     |       |

  54. | max_updates            | int(11) unsigned                  | NO   |     | 0                     |       |

  55. | max_connections        | int(11) unsigned                  | NO   |     | 0                     |       |

  56. | max_user_connections   | int(11) unsigned                  | NO   |     | 0                     |       |

  57. | plugin                 | char(64)                          | NO   |     | mysql_native_password |       |

  58. | authentication_string  | text                              | YES  |     | NULL                  |       |

  59. | password_expired       | enum('N','Y')                     | NO   |     | N                     |       |

  60. | password_last_changed  | timestamp                         | YES  |     | NULL                  |       |

  61. | password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |

  62. | account_locked         | enum('N','Y')                     | NO   |     | N                     |       |

  63. +------------------------+-----------------------------------+------+-----+-----------------------+-------+

  64. 45 rows in set (0.01 sec)


  65. mysql> select user,host,authentication_string,password_expired from user;

  66. +-----------+-----------+-------------------------------------------+------------------+

  67. | user      | host      | authentication_string                     | password_expired |

  68. +-----------+-----------+-------------------------------------------+------------------+

  69. | root      | localhost | *00881DDA4E834681A467780B1BFF03D913447683 | Y                |

  70. | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                |

  71. +-----------+-----------+-------------------------------------------+------------------+

  72. 2 rows in set (0.00 sec)

修改密码

  1. mysql> update user set authentication_string=password('123456'),password_expired='N' where user='root';

  2. mysql> flush privileges;

重启服务并使用root登录

  1. # /etc/init.d/mysql.server restart

  2. # /usr/local/mysql/bin/mysql -uroot -p

  3. Enter password: 

  4. Welcome to the MySQL monitor.  Commands end with ; or \g.

  5. Your MySQL connection id is 2

  6. Server version: 5.7.15 MySQL Community Server (GPL)


  7. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


  8. Oracle is a registered trademark of Oracle Corporation and/or its

  9. affiliates. Other names may be trademarks of their respective

  10. owners.


  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


  12. mysql> 

允许远程访问MySQL服务

开放3306 端口

  1. # firewall-cmd --zone=public --add-port=3306/tcp --permanent

  2. success

  3. # firewall-cmd --reload

  4. success

修改root用户的host为%

  1. mysql> update user set host='%' where user='root';

查看3306端口情况

  1. # netstat -tunlp |grep 3306

创建新用户并授权[可选方式]

  1. mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'userpassword';

MySQL日志如果有如下警告

  1. [Warning] IP address 'x.x.x.x' could not be resolved: Name or service not known

修改my.cnf文件,在[mysqld]下面添加skip-*如下,重启服务即可

  1. [mysqld]


  2. skip-host-cache

  3. skip-name-resolve

通过命令行远程连接,经测试Navicate连接正常【域名或IP地址】

  1. $ mysql -P3306 -uroot -hIP地址 -ppasswd


文章转载自大数据真有意思,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论