当前位置:网站首页>mysql使用笔记一
mysql使用笔记一
2022-06-27 18:55:00 【墨天轮】
MySQL和postgresql是目前比较火的两大开源数据库,绝大多数国产数据库都衍生于此,MySQL从整个架构上、设计上和语法上讲类似于早期的Sybase,SQLServer也源之于Sybase,从应用上讲SQLServer更友好,功能更丰富,单体数据库性能也是最好的;MySQL还有诸多的限制,不过这里只是试验和笔记,不做赘述。
1、第一次登陆MySQL,需要从日志从获取初始密码
[[email protected] local]# grep 'temporary password' /var/log/mysqld.log
2022-06-16T04:41:36.398736Z 6 [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 10
Server version: 8.0.29
Copyright (c) 2000, 2022, 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 1820 (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 1819 (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, 0 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 | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.02 sec)
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.check_user_name=off;
Query OK, 0 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 | 6 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 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 |
+-----------+------+
1 row in set (0.00 sec)
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user where user='root';
+------+------+
| host | user |
+------+------+
| % | root |
+------+------+
1 row in set (0.00 sec)
4、给root用户外部用户赋权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 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 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3667/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 5353/master
tcp 0 52 192.168.13.50:22 123.123.123.2:52521 ESTABLISHED 4618/sshd: [email protected]
tcp 0 0 192.168.13.50:22 192.168.13.11:63249 ESTABLISHED 4546/sshd: [email protected]
tcp 0 0 192.168.13.50:22 123.123.123.2:64545 ESTABLISHED 4569/sshd: [email protected]
tcp6 0 0 :::3306 :::* LISTEN 5439/mysqld
tcp6 0 0 :::22 :::* LISTEN 3667/sshd
tcp6 0 0 ::1:25 :::* LISTEN 5353/master
tcp6 0 0 :::33060 :::* LISTEN 5439/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=0.0.0.0
"/etc/my.cnf" 33L, 1265C written
[[email protected] local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[[email protected] local]# firewall-cmd --reload
success
[[email protected] local]#
最后,谢谢关注,谢谢支持!
边栏推荐
- OpenSSL client programming: SSL session failure caused by an obscure function
- Character interception triplets of data warehouse: substrb, substr, substring
- KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
- 实现字符串MyString
- Batch insert data using MySQL bulkloader
- Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
- 难怪大家丢掉了postman而选择 Apifox
- Csdn Skills Tree use Experience and Product Analysis (1)
- Necessary software tools in embedded software development
- Installing services for NFS
猜你喜欢
Installing services for NFS
On the drawing skills of my writing career
BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!
一套系统,减轻人流集中地10倍的通行压力
BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!
展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
Flood fighting and disaster relief, overcoming difficulties, and City United premium products rushed to the aid of Yingde to donate loving materials
基于微信小程序的高校党员之家服务管理系统系统小程序#毕业设计,党员,积极分子,学习,打卡,论坛
The meta universe virtual digital human is closer to us | Sinovel interaction
海量数据出席兰州openGauss Meetup(生态全国行)活动,以企业级数据库赋能用户应用升级
随机推荐
OpenSSL client programming: SSL session failure caused by an obscure function
shell脚本控制服务的启动和关闭 - 具备详细案例
安全高效,非接触“刷手”身份识别助力疫情防控
动物养殖生产虚拟仿真教学系统|华锐互动
[STL programming] [common competition] [Part 1]
爱数课实验 | 第七期-基于随机森林的金融危机分析
花了6个月时间完成本科优秀毕业设计,我做了什么?
Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)
众昂矿业:新能源或成萤石最大应用领域
ABAP-CL_ OBJECT_ Collection tool class
Necessary software tools in embedded software development
难怪大家丢掉了postman而选择 Apifox
Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)
Love math experiment | phase VI - Financial anti fraud case study
SQL audit platform permission module introduction and account creation tutorial
Unity3d button adapts the size according to the text content
#yyds干货盘点#SQL 子查询
Oracle 架构汇总
1027 Colors in Mars
Logcli Loki command line tool