1.什么是数据库
mariadb是mysql的分支 maria是数据库开发者的女儿
和mysql是完全兼容的
yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
#端口对外暴露 不安全
[root@server ~]# netstat -antlpe | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 79401 4279/mysqld
vim /etc/my.cnf
skip-networking=1
systemctl restart mariadb
[root@server ~]# netstat -antlpe | grep mysql
mysql -uroot
#数据库的查看
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
#切换到已经存在的数据库里
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]> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
#查看一个表中的全部内容
MariaDB [mysql]> SELECT * FROM user;
#安全初始化(给root用户给一个密码)
[root@server ~]# mysql_secure_installation
密码的登陆方式:
[root@server ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO
mysql -uroot -predhat
mysql -uroot -p #安全 比较推荐
[root@server ~]# mysql -uroot -predhat -e "SHOW DATABASES;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
#增删改查
1.查询
MariaDB [mysql]> desc user; #查看数据库中一个已经存在的表的结构
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
#根据表的信息去查找相应的数据
MariaDB [mysql]> select Host,User,Password,Insert_priv from user;
+-----------+------+-------------------------------------------+-------------+
| Host | User | Password | Insert_priv |
+-----------+------+-------------------------------------------+-------------+
| localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | Y |
| 127.0.0.1 | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | Y |
| ::1 | root | *84BB5DF4823DA