当前位置:网站首页>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]#
最后,谢谢关注,谢谢支持!
边栏推荐
猜你喜欢
Advanced C language -- function pointer
字节跳动高工面试,轻松入门flutter
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
网关Gateway的介绍与使用
字节跳动Android金三银四解析,android面试题app
DNS 系列(一):为什么更新了 DNS 记录不生效?
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
【DesignMode】代理模式(proxy pattern)
二叉搜索树(基操篇)
Lowcode: four ways to help transportation companies enhance supply chain management
随机推荐
skimage学习(1)
LeetCode 403. Frog crossing the river daily
【DesignMode】代理模式(proxy pattern)
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
面向接口编程
二叉搜索树(特性篇)
正在准备面试,分享面经
LeetCode 300. 最长递增子序列 每日一题
Localstorage and sessionstorage
如何在软件研发阶段落地安全实践
Lie cow count (spring daily question 53)
Binary search tree (features)
node:504报错
Direct dry goods, 100% praise
Read PG in data warehouse in one article_ stat
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
打造All-in-One应用开发平台,轻流树立无代码行业标杆
LeetCode 1654. The minimum number of jumps to get home one question per day
[Seaborn] implementation of combined charts and multi subgraphs
【DesignMode】模板方法模式(Template method pattern)