前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >mysql使用笔记一

mysql使用笔记一

作者头像
python与大数据分析
发布2022-07-07 15:25:53
发布2022-07-07 15:25:53
22900
代码可运行
举报
运行总次数:0
代码可运行

MySQL和postgresql是目前比较火的两大开源数据库,绝大多数国产数据库都衍生于此,MySQL从整个架构上、设计上和语法上讲类似于早期的Sybase,SQLServer也源之于Sybase,从应用上讲SQLServer更友好,功能更丰富,单体数据库性能也是最好的;MySQL还有诸多的限制,不过这里只是试验和笔记,不做赘述。

1、第一次登陆MySQL,需要从日志从获取初始密码

代码语言:javascript
代码运行次数:0
复制
[root@localhost local]# grep 'temporary password' /var/log/mysqld.log
-06-16T04::36.398736Z  [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: oyazXUIps8)F
[root@localhost local]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 
Server version: 8.0.29

Copyright (c) , , Oracle and/or its affiliates.

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.

2、各项操作前需要先更新初始密码,再修改符合需要的密码策略

代码语言:javascript
代码运行次数:0
复制
mysql> SHOW VARIABLES LIKE 'validate_password.%';
ERROR  (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234@abcd';
ERROR  (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1qaz!QAZ';
Query OK,  rows affected (0.01 sec)

mysql> SHOW VARIABLES LIKE 'validate_password.%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             |       |
| validate_password.mixed_case_count   |       |
| validate_password.number_count       |       |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count |       |
+--------------------------------------+--------+
 rows in set (0.02 sec)

mysql> set global validate_password.length=;
Query OK,  rows affected (0.00 sec)

mysql> set global validate_password.policy=;
Query OK,  rows affected (0.00 sec)

mysql> set global validate_password.check_user_name=off;
Query OK,  rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password.%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | OFF   |
| validate_password.dictionary_file    |       |
| validate_password.length             |      |
| validate_password.mixed_case_count   |      |
| validate_password.number_count       |      |
| validate_password.policy             | LOW   |
| validate_password.special_char_count |      |
+--------------------------------------+-------+
 rows in set (0.01 sec)

3、进入数据,修改用户表,确保外部用户可以访问MySQL

代码语言:javascript
代码运行次数:0
复制
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> select host,user from user where user='root';
+-----------+------+
| host      | user |
+-----------+------+
| localhost | root |
+-----------+------+
 row in set (0.00 sec)

mysql> update user set host='%' where user='root';
Query OK,  row affected (0.01 sec)
Rows matched:   Changed:   Warnings: 

mysql> select host,user from user where user='root';
+------+------+
| host | user |
+------+------+
| %    | root |
+------+------+
 row in set (0.00 sec)

4、给root用户外部用户赋权

代码语言:javascript
代码运行次数:0
复制
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ERROR  (): You are not allowed to create a user with GRANT
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK,  rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK,  rows affected (0.01 sec)

mysql> 

5、修改配置文件,绑定IP地址,再修改防火墙,确保外部用户能访问端口

代码语言:javascript
代码运行次数:0
复制
[root@localhost local]# netstat -anpt 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp               ...:              ...:*               LISTEN      /sshd           
tcp               127.0..:            ...:*               LISTEN      /master         
tcp              192.168.13.50:        123.123.123.2:     ESTABLISHED /sshd: root@pts 
tcp               192.168.13.50:        192.168.13.11:     ESTABLISHED /sshd: root@pts 
tcp               192.168.13.50:        123.123.123.2:     ESTABLISHED /sshd: root@pts 
tcp6              :::                 :::*                    LISTEN      /mysqld         
tcp6              :::                   :::*                    LISTEN      /sshd           
tcp6              :::                  :::*                    LISTEN      /master         
tcp6              :::                :::*                    LISTEN      /mysqld         
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost local]# vi /etc/my.cnf  
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

bind-address=...
"/etc/my.cnf" L, C written
[root@localhost local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost local]# firewall-cmd --reload 
success
[root@localhost local]# 

最后,谢谢关注,谢谢支持!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-06-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 python与大数据分析 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档