Linux(Centos)在线安装MySql

1、新创建的服务器,需要检测系统是否自带安装mysql

  1. # yum list installed | grep mysql

2、如果发现有系统自带mysql,请卸载

  1. # yum -y remove mysql-libs.x86_64

3、下载mysql yum源

  1. # wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

4、配置MySQL的安装源

  1. # rpm -ivh mysql-community-release-el6-5.noarch.rpm

5、安装mysql 服务器命令

  1. # yum install mysql-community-server

6、安装成功后启动

  1. # service mysqld start

7、由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码

  1. # mysql
  2. # show databases;
  3. +——————————+
  4. | Database |
  5. +——————————+
  6. | information_schema |
  7. | hive |
  8. | mysql |
  9. | performance_schema |
  10. +——————————+
  11. # use mysql;
  12. # show tables;
  13. +—————————————-+
  14. | Tables_in_mysql |
  15. +—————————————-+
  16. | columns_priv |
  17. | db |
  18. | event |
  19. | func |
  20. | general_log |
  21. | help_category |
  22. | help_keyword |
  23. | help_relation |
  24. | help_topic |
  25. | innodb_index_stats |
  26. | innodb_table_stats |
  27. | ndb_binlog_index |
  28. | plugin |
  29. | proc |
  30. | procs_priv |
  31. | proxies_priv |
  32. | servers |
  33. | slave_master_info |
  34. | slave_relay_log_info |
  35. | slave_worker_info |
  36. | slow_log |
  37. | tables_priv |
  38. | time_zone |
  39. | time_zone_leap_second |
  40. | time_zone_name |
  41. | time_zone_transition |
  42. | time_zone_transition_type |
  43. | user |
  44. +—————————————-+
  45. # select host,user from user;
  46. +—————-+———+
  47. | host | user |
  48. +—————-+———+
  49. | 127.0.0.1 | root |
  50. | ::1 | root |
  51. | localhost | |
  52. | slave1 | |
  53. | slave1 | root |
  54. +—————-+———+
  55. # grant all privileges on . to ‘root’@’%’ identified by ‘root’ with grant option;
  56. # select host,user from user;
  57. +—————-+———+
  58. | host | user |
  59. +—————-+———+
  60. | % | root |
  61. | 127.0.0.1 | root |
  62. | ::1 | root |
  63. | localhost | |
  64. | slave1 | |
  65. | slave1 | root |
  66. +—————-+———+
  67. # delete from user where host != ‘%’;
  68. # select host,user from user;
  69. +———+———+
  70. | host | user |
  71. +———+———+
  72. | % | root |
  73. +———+———+
  74. # flush privileges;
  75. # quit ;
  76. # service mysqld restart ;
  77. # mysql -uroot -proot;
  78. # show databases;
  79. +——————————+
  80. | Database |
  81. +——————————+
  82. | information_schema |
  83. | hive |
  84. | mysql |
  85. | performance_schema |
  86. +——————————+
  87. 4 rows in set (0.00 sec)
  88. 8、查看mysql是否自启动,并且设置开启自启动命令
  89. # chkconfig —list | grep mysqld
  90. # chkconfig mysqld on

9、mysql安全设置

  1. # mysql_secure_installation

Mysql5.7数据库初始密码查看及修改

自Mysql5.7初始密码不再默认为空!!!

1.查看初始密码:

  1. [root@master]# grep temporary password /var/log/mysqld.log
  2. 2017-03-12T12:25:43.090102Z 1 [Note] A temporary password is generated for root@localhost: h8&%pgp/+BB2

2.登录及修改密码:

  1. [root@master]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 3
  5. Server version: 5.7.17
  6. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type help;’ or \h for help. Type \c to clear the current input statement.
  11. mysql> show databases;
  12. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

3.修改密码:

  1. mysql> alter user root@localhost identified by Mysql123#’;
  2. Query OK, 0 rows affected (0.00 sec)