kali linux----mysql数据库启用、查询、建库、建表、建列

kali linux—-mysql数据库启用、查询、建库、建表、建列

使用kali linux安装mysql完毕后,操作如下:

1、mysql的my.cnf内容变更
参考:https://blog.csdn.net/gvfdbdf/article/details/49150361

root@kali:~# ls /etc/mysql/
conf.d  debian.cnf  debian-start  mariadb.cnf  mariadb.conf.d  my.cnf  my.cnf.fallback
root@kali:~# cat /etc/mysql/my.cnf
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
root@kali:~# 
root@kali:~# cd /etc/mysql/
root@kali:/etc/mysql# ls
conf.d  debian.cnf  debian-start  mariadb.cnf  mariadb.conf.d  my.cnf  my.cnf.fallback
root@kali:/etc/mysql# cp my.cnf my.cnf.bak
root@kali:/etc/mysql# ls
conf.d  debian.cnf  debian-start  mariadb.cnf  mariadb.conf.d  my.cnf  my.cnf.bak  my.cnf.fallback
root@kali:/etc/mysql# vi my.cnf
变更的内容如下:

root@kali:~# cat /etc/mysql/my.cnf
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
#[client-server]
[client]  
default-character-set = utf8  

[mysqld]  
default-storage-engine = INNODB  
character-set-server = utf8  
collation-server = utf8_general_ci

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
root@kali:~# 
2、mysql的启用

root@kali:/etc/mysql# /etc/init.d/mysql status
● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql; generated; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
root@kali:/etc/mysql# /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
root@kali:/etc/mysql#

#检查Mysql是否正在运行
root@kali:~/pywork# sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN      4046/mysqld         

#如果服务器不能正常运行,您可以通过下列命令启动它:
root@kali:~/pywork# sudo /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.
root@kali:~/pywork# 
3、进入mysql、更改用户、更改密码、实时更新数据
参考:https://blog.csdn.net/gvfdbdf/article/details/49150361”

root@kali:/etc/mysql# mysql -u root#使用root用户登录
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.1.26-MariaDB-1 Debian buildd-unstable

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

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

MariaDB [(none)]> use mysql#使用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]> update user set password=PASSWORD('root') where User='root';#把用户root的登陆密码,更改密码为root
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;#实时更新被更改的数据
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> quit
Bye
root@kali:/etc/mysql# /etc/init.d/mysql restart#重启mysql服务
[ ok ] Restarting mysql (via systemctl): mysql.service.
4、使用最新的root用户与密码root登陆进去,增加数据、删除数据、查询数据
参考:https://blog.csdn.net/qq_36000140/article/details/60963365
https://www.cnblogs.com/chencye/p/5827997.html
https://blog.csdn.net/u010746364/article/details/53078550

root@kali:/etc/mysql# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.1.26-MariaDB-1 Debian buildd-unstable

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

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

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS python3db DEFAULT CHARSET utf8;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]>
MariaDB [(none)]> show databases;#查看所有的数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| python3db          |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use python3db#使用数据库python3db进入
Database changed
MariaDB [python3db]> show tables;#显示数据库python3db的数据表
Empty set (0.00 sec)
MariaDB [python3db]> CREATE TABLE user (name VARCHAR(20), sex CHAR(1), birth DATE, birthaddr VARCHAR(20));#创建数据
Query OK, 0 rows affected (0.07 sec)

MariaDB [python3db]> show tables;
+---------------------+
| Tables_in_python3db |
+---------------------+
| user                |
+---------------------+
1 row in set (0.00 sec)
MariaDB [python3db]> DESCRIBE user;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| name      | varchar(20) | YES  |     | NULL    |       |
| sex       | char(1)     | YES  |     | NULL    |       |
| birth     | date        | YES  |     | NULL    |       |
| birthaddr | varchar(20) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
MariaDB [python3db]> select * from user;
Empty set (0.00 sec)
MariaDB [python3db]> insert into user values('python3','f','2017-06-21','shenzhen') ;
Query OK, 1 row affected (0.01 sec)

MariaDB [python3db]> insert into user values('python3','m','2018-05-01','hangzhou');
Query OK, 1 row affected (0.00 sec)
MariaDB [python3db]> select * from user;
+---------+------+------------+-----------+
| name    | sex  | birth      | birthaddr |
+---------+------+------------+-----------+
| python3 | f    | 2017-06-21 | shenzhen  |
| python3 | m    | 2018-05-01 | hangzhou  |
+---------+------+------------+-----------+
2 rows in set (0.00 sec)

MariaDB [python3db]> insert into user values('lilei','m','2018-05-01','hangzhou');
Query OK, 1 row affected (0.00 sec)

MariaDB [python3db]> insert into user values('mayun','m','2019-05-01','guagzhou');
Query OK, 1 row affected (0.00 sec)

MariaDB [python3db]> insert into user values('mayun','f','2019-05-23','dayuan');
Query OK, 1 row affected (0.00 sec)

MariaDB [python3db]> 
MariaDB [python3db]> select * from user;
+---------+------+------------+-----------+
| name    | sex  | birth      | birthaddr |
+---------+------+------------+-----------+
| python3 | f    | 2017-06-21 | shenzhen  |
| python3 | m    | 2018-05-01 | hangzhou  |
| lilei   | m    | 2018-05-01 | hangzhou  |
| mayun   | m    | 2019-05-01 | guagzhou  |
| mayun   | f    | 2019-05-23 | dayuan    |
+---------+------+------------+-----------+
5 rows in set (0.00 sec)

MariaDB [python3db]>
MariaDB [python3db]> show tables;
+---------------------+
| Tables_in_python3db |
+---------------------+
| user                |
+---------------------+
1 row in set (0.00 sec)

MariaDB [python3db]> 
MariaDB [python3db]> show columns from user;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| name      | varchar(20) | YES  |     | NULL    |       |
| sex       | char(1)     | YES  |     | NULL    |       |
| birth     | date        | YES  |     | NULL    |       |
| birthaddr | varchar(20) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MariaDB [python3db]> 

猜你喜欢

转载自blog.csdn.net/xwbk12/article/details/80768969