MySQL 配置及添加數據庫

Platform: Linux kali 5.3.0-kali2-amd64 #1 SMP Debian 5.3.9-3kali1 (2019-11-20) x86_64 GNU/Linux
MySQL: mysql Ver 15.1 Distrib 10.3.20-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

MySQL 配置


  • 修改監聽地址和端口, 配置文件/etc/mysql/mariadb.conf.d/50-server.cnf
port                   = 3306
bind-address           = 0.0.0.0
  • 配置修改後,重啓 mysql.service 配置即可生效
root@kali:~# netstat -ln | more
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN 
  • 修改密碼
mysqladmin -u root -p current_password password new_password
  • 連接 MySQL
root@kali:~# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.3.20-MariaDB-1 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
  • 查看 user
MariaDB [(none)]> 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
MariaDB [mysql]> select user,host from user;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.000 sec)
  • 添加一個可以遠程連接數據庫的用戶
MariaDB [mysql]> insert into user 
    -> (host,user,password,ssl_cipher,x509_issuer,x509_subject,authentication_string)
    -> values
    -> ('%','xufc',PASSWORD('coco'),'','','',PASSWORD('coco'));
Query OK, 1 row affected (0.000 sec)

MariaDB [mysql]> select host,user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | xufc |
| localhost | root |
+-----------+------+
2 rows in set (0.000 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> quit
Bye
  • 添加 database,並授予用戶到該數據庫的權限
MariaDB [(none)]> create database BugStatis;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> GRANT ALL privileges ON BugStatis.* TO 'xufc'@'%';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| BugStatis          |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)

VS Code 連接數據庫


  • 通過 VS Code 遠程連接 MySQL遠程連接 MySQL

  • 通過 VS Code 連接數據庫連接數據庫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章