当前位置:网站首页>mysql使用笔记一
mysql使用笔记一
2022-07-07 15:33:00 【python与大数据分析】
MySQL和postgresql是目前比较火的两大开源数据库,绝大多数国产数据库都衍生于此,MySQL从整个架构上、设计上和语法上讲类似于早期的Sybase,SQLServer也源之于Sybase,从应用上讲SQLServer更友好,功能更丰富,单体数据库性能也是最好的;MySQL还有诸多的限制,不过这里只是试验和笔记,不做赘述。
1、第一次登陆MySQL,需要从日志从获取初始密码
[[email protected] local]# grep 'temporary password' /var/log/mysqld.log
-06-16T04::36.398736Z [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: oyazXUIps8)F
[[email protected] 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、各项操作前需要先更新初始密码,再修改符合需要的密码策略
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 '[email protected]';
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
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用户外部用户赋权
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地址,再修改防火墙,确保外部用户能访问端口
[[email protected] 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: [email protected]
tcp 192.168.13.50: 192.168.13.11: ESTABLISHED /sshd: [email protected]
tcp 192.168.13.50: 123.123.123.2: ESTABLISHED /sshd: [email protected]
tcp6 ::: :::* LISTEN /mysqld
tcp6 ::: :::* LISTEN /sshd
tcp6 ::: :::* LISTEN /master
tcp6 ::: :::* LISTEN /mysqld
pid-file=/var/run/mysqld/mysqld.pid
[[email protected] 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
[[email protected] local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[[email protected] local]# firewall-cmd --reload
success
[[email protected] local]#
最后,谢谢关注,谢谢支持!
边栏推荐
猜你喜欢
QT 图片背景色像素处理法
Module VI
A tour of gRPC:03 - proto序列化/反序列化
QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
直接上干货,100%好评
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
[medical segmentation] attention Unet
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
Horizontal and vertical centering method and compatibility
随机推荐
【PHP】PHP接口继承及接口多继承原理与实现方法
Direct dry goods, 100% praise
Talk about the realization of authority control and transaction record function of SAP system
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
二叉搜索树(基操篇)
模块六
Blue Bridge Cup final XOR conversion 100 points
LeetCode 1043. 分隔数组以得到最大和 每日一题
字节跳动高工面试,轻松入门flutter
【DesignMode】外观模式 (facade patterns)
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
Interface oriented programming
第九届 蓝桥杯 决赛 交换次数
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
LeetCode 1654. The minimum number of jumps to get home one question per day
Sort out several important Android knowledge and advanced Android development interview questions
DNS 系列(一):为什么更新了 DNS 记录不生效?
Cesium (4): the reason why gltf model is very dark after loading
LeetCode 1049. 最后一块石头的重量 II 每日一题
Seaborn数据可视化