Centos7下MySql5.7安装及配置
Posted Focus·Flying
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7下MySql5.7安装及配置相关的知识,希望对你有一定的参考价值。
安装mysql
软件包:
- mysql-community-libs-5.7.22-1.el7.x86_64.rpm
- mysql-community-common-5.7.22-1.el7.x86_64.rpm
- mysql-community-client-5.7.22-1.el7.x86_64.rpm
- mysql-community-server-5.7.22-1.el7.x86_64.rpm
安装流程(有依赖关系)
rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
配置MySql
- 启动MySql服务
systemctl start mysqld.service
- 查看MySql服务状态
systemctl status mysqld.service
- 使用RPM软件包进行安装会生成一个初始随机密码,该密码被写入服务器错误日志(/var/log/mysqld.log)。
[[email protected] ~]$ grep ‘temporary password‘ /var/log/mysqld.log
2018-07-10T12:35:03.497044Z 1 [Note] A temporary password is generated for [email protected]: (hfu*hjnt3W;
- 使用
mysql
命令, 用户名root
及得到的随机密码登入MySql服务器进行密码修改
[[email protected] ~]$ mysql -u root -p
Enter password: (hfu*hjnt3W;
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘new_password‘;
注意:
new_password
长度必须大于8个字符,且有大小写、数字、特殊字符。
- 在防火墙中开启3306端口(MySql服务器莫扔过高端口)并查看端口状态
shell> firewall-cmd --zone=public --add-port=3306/tcp --permanent
shell> firewall-cmd --reload
shell> firewall-cmd --zone=public --list-ports
小技巧
- 使用
mysqlshow
查看存在那些数据库或数据库中存在的表列表
shell> mysqlshow -u root -p
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
shell> mysqlshow -u root -p mysql
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
以上是关于Centos7下MySql5.7安装及配置的主要内容,如果未能解决你的问题,请参考以下文章