Linux之数据库的简单管理

ubuntu17.04 UHD 驱动出错 ubuntu 17.04 源码安装UHD 阅读详情

数据库

安装数据库

第一步:安装数据库(mariadb)服务

[root@mysql ~]# yum install mariadb.x86_64 
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.52-1.el7,它被软件包 1:mariadb-5.5.52-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.35-3.el7 将被 升级
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package              架构           版本                   源             大小
================================================================================
正在安装:
 mariadb              x86_64         1:5.5.52-1.el7         rhel7         8.6 M
为依赖而更新:
 mariadb-libs         x86_64         1:5.5.52-1.el7         rhel7         761 k

事务概要
================================================================================
安装  1 软件包
升级           ( 1 依赖软件包)

总下载量:9.4 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for rhel7
(1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm                | 761 kB   00:00     
(2/2): mariadb-5.5.52-1.el7.x86_64.rpm                     | 8.6 MB   00:00     
--------------------------------------------------------------------------------
总计                                                37 MB/s | 9.4 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : 1:mariadb-libs-5.5.52-1.el7.x86_64                          1/3 
  正在安装    : 1:mariadb-5.5.52-1.el7.x86_64                               2/3 
  清理        : 1:mariadb-libs-5.5.35-3.el7.x86_64                          3/3 
  验证中      : 1:mariadb-5.5.52-1.el7.x86_64                               1/3 
  验证中      : 1:mariadb-libs-5.5.52-1.el7.x86_64                          2/3 
  验证中      : 1:mariadb-libs-5.5.35-3.el7.x86_64                          3/3 

已安装:
  mariadb.x86_64 1:5.5.52-1.el7                                                 

作为依赖被升级:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                            

完毕!

第二步:开启数据库服务,并设置开机自启

##开启数据库服务
[root@mysql ~]# systemctl start mariadb
##设置开机自启动
[root@mysql ~]# systemctl enable mariadb
ln -s ‘/usr/lib/systemd/system/mariadb.service’ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service’

第三步:关闭数据库接口

##搜索mysql的接口
[root@mysql ~]# netstat -antuple | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 75183 3937/mysqld
##修改文件,使其接口对外开放关闭
[root@mysql ~]# vim /etc/my.cnf
skip-networking=1
在这里插入图片描述
##重启服务
[root@mysql ~]# systemctl restart mariadb
##查看接口为空
[root@mysql ~]# netstat -antuple | grep mysql

第四步:设定数据库安全初始化

##mysql密码初始化
[root@mysql ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

数据库安全设置完成后,进入数据库需要输入密码
格式:mysql -u用户 -p密码 退出— quit
在这里插入图片描述

u和用户,p和密码之间没有空格

数据库中的基础命令

##显示数据库——SHOW DATABASES;

##显示数据库中包含的所有数据库

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

在这里插入图片描述
##进入数据库——USE mysql;
##切换到mysql数据库中

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;

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                      |
+---------------------------+
24 rows in set (0.00 sec)

在这里插入图片描述
##.查询表结构

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       |       |
| Delete_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Create_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Drop_priv              | enum('N','Y')                     | NO   |     | N       |       |
| Reload_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Shutdown_priv          | enum('N','Y')                     | NO   |     | N       |       |
| Process_priv           | enum('N','Y')                     | NO   |     | N       |       |
| File_priv              | enum('N','Y')                     | NO   |     | N       |       |
| Grant_priv             | enum('N','Y')                     | NO   |     | N       |       |
| References_priv        | enum('N','Y')                     | NO   |     | N       |       |
| Index_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Alter_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Show_db_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Super_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N       |       |
| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Execute_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N       |       |
| Repl_client_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Create_view_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Show_view_priv         | enum('N','Y')                     | NO   |     | N       |       |
| Create_routine_priv    | enum('N','Y')                     | NO   |     | N       |       |
| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N       |       |
| Create_user_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Event_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Trigger_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N       |       |
| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |         |       |
| ssl_cipher             | blob                              | NO   |     | NULL    |       |
| x509_issuer            | blob                              | NO   |     | NULL    |       |
| x509_subject           | blob                              | NO   |     | NULL    |       |
| max_questions          | int(11) unsigned                  | NO   |     | 0       |       |
| max_updates            | int(11) unsigned                  | NO   |     | 0       |       |
| max_connections        | int(11) unsigned                  | NO   |     | 0       |       |
| max_user_connections   | int(11)                           | NO   |     | 0       |       |
| plugin                 | char(64)                          | NO   |     |         |       |
| authentication_string  | text                              | NO   |     | NULL    |       |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.00 sec)

在这里插入图片描述
##查询表中的信息

MariaDB [mysql]> SELECT Host,User,Password FROM user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| 127.0.0.1 | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| ::1       | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)

在这里插入图片描述

##新建数据库

MariaDB [mysql]> CREATE DATABASE westos;
Query OK, 1 row affected (0.00 sec)

MariaDB [mysql]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

在这里插入图片描述
##新建数据库中的表

MariaDB [mysql]> USE westos
Database changed
MariaDB [westos]> SHOW TABLE;
MariaDB [westos]> SHOW TABLES;
Empty set (0.00 sec)

MariaDB [westos]> CREATE TABLE linux (
    -> username varchar(20) not null,
    -> password varchar(10) not null);
Query OK, 0 rows affected (0.01 sec)

MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| linux            |
+------------------+
1 row in set (0.00 sec)

-> username varchar(20) not null, ##字符类型为char,不能为空
-> password varchar(10) not null ##字符类型为char,不能为空
在这里插入图片描述
##在linux表格中插入信息

MariaDB [westos]> INSERT INTO linux values('cai','123');
Query OK, 1 row affected (0.01 sec)

MariaDB [westos]> SELECT * FROM linux;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 123      |
+----------+----------+
1 row in set (0.00 sec)

select * from linux; ##查看linux表格中的所有信息
在这里插入图片描述

##修改增加表属性
在linux表格中添加age字段

MariaDB [westos]> ALTER TABLE linux ADD age varchar(8) after username;
Query OK, 1 row affected (0.01 sec)                
Records: 1  Duplicates: 0  Warnings: 0

MariaDB [westos]> SELECT * FROM linux;
+----------+------+----------+
| username | age  | password |
+----------+------+----------+
| cai      | NULL | 123      |
+----------+------+----------+
1 row in set (0.00 sec)

在这里插入图片描述
##修改删除表属性
在linux表格中移除age字段

MariaDB [westos]> ALTER TABLE linux DROP age;
Query OK, 1 row affected (0.02 sec)                
Records: 1  Duplicates: 0  Warnings: 0

MariaDB [westos]> SELECT * FROM linux;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 123      |
+----------+----------+
1 row in set (0.00 sec)

在这里插入图片描述
##修改linux表格中的信息(例:password)

MariaDB [westos]> SELECT * FROM linux;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 123      |
+----------+----------+
1 row in set (0.00 sec)

MariaDB [westos]> UPDATE linux SET password='110' WHERE username='cai';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [westos]> SELECT * FROM linux;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 110      |
+----------+----------+
1 row in set (0.00 sec)

在这里插入图片描述
##修改表格名字

MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| linux            |
+------------------+
1 row in set (0.00 sec)

MariaDB [westos]> ALTER TABLE linux RENAME westos;
Query OK, 0 rows affected (0.00 sec)

MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| westos           |
+------------------+
1 row in set (0.00 sec)

在这里插入图片描述
##删除表格中的某一行

MariaDB [westos]> SELECT * FROM westos;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 110      |
+----------+----------+
1 row in set (0.00 sec)

MariaDB [westos]> INSERT INTO westos values('tian','456');
Query OK, 1 row affected (0.01 sec)

MariaDB [westos]> SELECT * FROM westos;
+----------+----------+
| username | password |
+----------+----------+
| cai      | 110      |
| tian     | 456      |
+----------+----------+
2 rows in set (0.00 sec)

MariaDB [westos]> DELETE FROM westos WHERE username='cai';
Query OK, 1 row affected (0.00 sec)

MariaDB [westos]> SELECT * FROM westos;
+----------+----------+
| username | password |
+----------+----------+
| tian     | 456      |
+----------+----------+
1 row in set (0.00 sec)

在这里插入图片描述
##删除表格

MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| westos           |
+------------------+
1 row in set (0.00 sec)

MariaDB [westos]> DROP TABLE westos;
Query OK, 0 rows affected (0.01 sec)

MariaDB [westos]> SHOW TABLES;
Empty set (0.00 sec)

在这里插入图片描述
##删除数据库

MariaDB [westos]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [westos]> DROP DATABASE westos;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

在这里插入图片描述

数据库用户管理(创建用户、授权、取消授权、修改密码)

##创建用户

MariaDB [(none)]> CREATE DATABASE westos;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> USE westos;
Database changed
MariaDB [westos]> CREATE TABLE linux(
    -> username varchar(20) not null,
    -> password varchar(10) not null);
Query OK, 0 rows affected (0.01 sec)

MariaDB [westos]> INSERT INTO linux values('hello','123');
Query OK, 1 row affected (0.00 sec)

MariaDB [westos]> INSERT INTO linux values('cai','123');
Query OK, 1 row affected (0.00 sec)

##创建用户(root用户),并用新建的用户登陆
##hate@localhost 本地用户 ##hate@‘%’ 远程用户

##以数据库root用户进行登陆
[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 5.5.52-MariaDB MariaDB Server

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

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

##创建用户cai,密码为123
MariaDB [(none)]> CREATE USER cai@localhost identified by '123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
##以数据库cai用户进行登陆
[root@mysql ~]# mysql -ucai -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 |
+--------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 

在这里插入图片描述
##给用户授权

##使用数据库root用户登陆
[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 5.5.52-MariaDB MariaDB Server

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

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

##授予cai用户查询、更新、删除、插入权限。
mysql.*代表授予ajie的权限对数据库mysql下的所有表单有效
MariaDB [(none)]> GRANT select,update,delete,insert ON mysql.* TO cai@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
##使用数据库cai用户登陆
[root@mysql ~]# mysql -ucai -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.52-MariaDB MariaDB Server

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

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

###此时查看所有数据库的时候,可以看到有mysql了
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

#查看数据库mysql中的所有表单
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                      |
+---------------------------+
24 rows in set (0.00 sec)

MariaDB [mysql]> 

在这里插入图片描述

数据库用户密码的修改

##修改root用户密码(记得密码)

##使用数据库root用户登陆
[root@mysql ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 5.5.52-MariaDB MariaDB Server

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

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

##修改密码为123 此方式属于加密修改,数据库中看不到root用户密码
MariaDB [(none)]> SET password = PASSWORD('123');
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

在这里插入图片描述

##修改root用户密码(忘记密码)

##停止mariadb服务
[root@mysql ~]# systemctl stop mariadb
##跳过密码验证
[root@mysql ~]# mysqld_safe --skip-grant-tables &
[1] 3399
[root@mysql ~]# 190813 09:51:58 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
190813 09:51:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^C
##直接免密登陆
[root@mysql ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.52-MariaDB MariaDB Server

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

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

##修改密码为789,这种修改方式在数据库中可以看到密码
MariaDB [(none)]> UPDATE mysql.user SET password='789' WHERE User='root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0

##看到密码为789
MariaDB [(none)]> SELECT *FROM mysql.user;
+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| Host      | User   | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string |
+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| localhost | root   | 789                                       | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| 127.0.0.1 | root   | 789                                       | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| ::1       | root   | 789                                       | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| localhost | cai    | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| localhost | westos | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
5 rows in set (0.00 sec)

##修改密码为123,这种修改方式在数据库中不能看到密码
MariaDB [(none)]> UPDATE mysql.user SET password=password('123') WHERE User='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

##密码为加密字符
MariaDB [(none)]> SELECT *FROM mysql.user;+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| Host      | User   | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string |
+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| localhost | root   | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| 127.0.0.1 | root   | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| ::1       | root   | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| localhost | cai    | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
| localhost | westos | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 |        |                       |
+-----------+--------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
5 rows in set (0.00 sec)

##刷新MySQL的系统权限相关表
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

##退出数据库
MariaDB [(none)]> quit
Bye
##查询跳过服务的进程,必须要关闭该进程,否则一直免密登陆
[root@mysql ~]# ps -aux | grep mysql
root      3399  0.0  0.1 113248  1568 pts/1    S    09:51   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql     3554  0.0  8.7 843956 84648 pts/1    Sl   09:51   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root      3612  0.0  0.0 112656   944 pts/1    R+   09:53   0:00 grep --color=auto mysql
##关闭进程
[root@mysql ~]# kill -9 3399
[root@mysql ~]# kill -9 3554
[1]+  已杀死               mysqld_safe --skip-grant-tables
##开启mariadb服务
[root@mysql ~]# systemctl start mariadb
##免密登陆不行
[root@mysql ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
##用修改后的密码登陆
[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.52-MariaDB MariaDB Server

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

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

MariaDB [(none)]> quit
Bye
[root@mysql ~]# 

在这里插入图片描述
在这里插入图片描述

数据库的备份

第一步:备份userdata库,且导入/xxx/userdata.sql文件—— mysqldump -uroot -predhat userdata > /xxx/userdata.sql

##使用root去备份,-p代表它有密码,westos为要备份的数据库,备份到/mnt/下名称为backup_westos.dump
[root@mysql ~]# mysqldump -u root -p westos > /mnt/back_westos.dump
Enter password:
##查看文件是否生成
[root@mysql ~]# ls /mnt/
back_westos.dump

第二步:删除数据库wechat中的表单myid的数据

[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> DROP DATABASE westos;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye

第三步:恢复数据库

[root@mysql ~]# mysql -uroot -p westos < /mnt/back_westos.dump#输入重定向来导入数据westos进行还原
Enter password: 
[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

单细胞分析实战:当Seurat的SCTransform遇上Harmony,我的整合流程优化笔记 本文详细介绍了单细胞转录组数据分析中SCTransform与Harmony整合流程的优化策略。通过实战案例展示如何调整SCTransform参数、优化Harmony整合效果,并解决常见问题,帮助研究者获得更可靠的生物学发现。特别适合需要处理批次效应的单细胞数据分析人员。 阅读详情

相关推荐

HDMI设计2----EDID and E-EDID

1,EDID是什么?有什么用? 图1 应用场景 如图1所示的应用场景,PC将视频信号发送 到我们的设备上,经过一系列的传输和切换,设备将视频信号发送到显示器或者投影机上,也就是说,我们的设备位于PC和显示器之间。首先,在输入端,设备需要让PC知道自己是能够接受输入视频信号的,让PC认为自己是一台显示器。如果不这样做的话,PC可能会拒绝输出任何视频信号的(VGA接口不需要EDID也能输出)。除此之外,设备还要告诉PC自己支持的显示时序。而在输出端,当设备需要自建输出时序而不是简单的复制...

Archar_Saber的博客 7988

camunda自动建表失败解决

com.mysql.cj.jdbc.NonRegisteringDriver#connect 找到conStr,里面包含的property是jdbcUrl的属性,所以在url后面加上nullDatabaseMeansCurrent​​​​​​​=true即可。com.mysql.cj.jdbc.ConnectionImpl#ConnectionImpl(com.mysql.cj.conf.HostInfo) 从HostInfo中获取属性。这个属性从conn获取,key是。propertySet怎么赋值。

m0_70543624的博客 4133

从仿真到部署:基于ROS2与Gazebo的UR5e机械臂全流程控制实践

本文详细介绍了基于ROS2与Gazebo的UR5e机械臂全流程控制实践,从环境准备、模型构建到控制器开发和仿真优化,最终实现真实机器人部署。通过实战案例和避坑指南,帮助开发者掌握机器人仿真与控制的关键技术,提升UR5e机械臂在物料分拣等任务中的性能与稳定性。

weixin_29184371的博客 288

activiti7关联mysql_学习笔记:一个MySQL实例有多个Activiti数据库问题

学习笔记:一个MySQL实例有多个Activiti数据库问题使用SpringBoot + activiti6 搭建审批流项目,数据库使用的是MySQL.且我的数据库下存在多个activiti相关的数据库 schema.org.activitiactiviti-spring-boot-starter-basic6.0.0配置文件spring.datasource.driver-class-name=...

weixin_28987001的博客 670

RK3588 MIPI屏幕调试避坑指南:双通道8Lane下DSC压缩屏的花屏、分层问题排查实录

本文详细解析了RK3588平台在双通道8Lane MIPI接口下调试DSC压缩屏时遇到的花屏、分层问题。通过硬件信号完整性检查、软件配置验证及帧数据分析,提供了一套系统化的排查方法,并深入探讨了初始化序列优化和双通道同步机制,帮助工程师高效解决高分辨率屏幕显示异常问题。

weixin_27015733的博客 280

KEPServerEX实战:Modbus TCP与RTU双协议配置详解

本文详细解析了如何使用KEPServerEX软件同时配置与管理Modbus TCP和RTU混合网络。通过实战步骤,指导用户建立双协议通道、配置设备与标签,并分享核心的地址映射规则与通讯故障排查技巧,帮助工业自动化工程师高效集成多协议设备,简化数据采集架构。

weixin_29186249的博客 397

mysql数据库设置

character_set_server:默认的内部操作字符集character_set_client:客户端来源数据使用的字符集character_set_connection:连接层字符集 删除列要用drop选b 删除表要用DROP TABLE选d

lwguang0612的博客 306

手把手教你学基带SOC芯片(4.4.9)--基带芯片的电源管理实例:高通 Snapdragon 系列实例(十)

Snapdragon 888 通过支持多种深度睡眠模式,如 AOAC 模式、低功耗模式和深度睡眠模式,以及智能电源管理技术,实现了对功耗的精细管理。这些模式不仅延长了设备的电池寿命,还确保了用户在各种使用场景下的良好体验。无论是保持网络连接、限制后台活动,还是完全关闭不必要的功能,Snapdragon 888 都能够灵活应对,提供高效的功耗管理方案。

MHD0815的博客 740

MySQL连接遇到的问题

关于使用mysql 8版本以上的朋友 肯定会遇到这些问题 ! 连接时区问题 自动创建表问题 什么主键问题 等等等等 这遍文章都可以给你解决掉 8版本的驱动,弃用了原来的方法,我们直接去看源码也能找到。 com.mysql.jdbc.Driver里面有两句话 Loading class `com.mysql.jdbc.Driver'. This is deprec...

日日言谧 1470

生产环境中redis的SCAN命令如何替代KEYS命令?

本文介绍了使用SCAN命令替代KEYS的完整方案。SCAN通过游标分批迭代,避免KEYS命令遍历整个键空间导致的阻塞风险。文章详细说明了SCAN的基础语法、迭代流程和Java实现示例,强调必须关闭Cursor避免连接泄漏。针对生产环境,提供了COUNT参数调优、客户端去重、集群模式适配等优化建议,并列举了典型错误场景。SCAN通过分批次迭代和游标管理,可安全实现高性能键空间遍历。全文150字。

DN金猿的博客 179

实现航迹关联的三种JPDA算法及Matlab代码

本文介绍了三种不同的JPDA算法实现航迹关联,并提供相应的Matlab代码。卡尔曼滤波是一种常用的状态估计算法,其基本思想是根据系统模型和观测数据,通过迭代计算来更新系统状态的估计值。基于卡尔曼滤波的JPDA算法是指在航迹关联问题中,同时利用卡尔曼滤波器的状态估计和概率假设,从而确定目标之间的关联关系。基于粒子滤波的JPDA算法是指在航迹关联问题中,通过抽样生成一组粒子(代表系统的不同可能状态),从而计算目标之间的关联概率。基于启发式搜索的JPDA算法是指在航迹关联问题中,通过多次迭代寻找最优关联方案。

code_welike的博客 1831

MySQL {term}.format(term=terms)解决筛选问题

问题:数据表中某一字段(假设为os)的存值是各个主机的操作系统,现在想在页面中归纳操作系统,并根据归纳后的操作系统类别进行搜索,搜索项有“CentOS”、“Ubuntu”、“RedHat”、“SUSE”、“其他”,“所有”,对应的前端设计传值为“CentOS”、“Ubuntu”、“RedHat”、“SUSE”,“others”,“” 数据库数据内容: mysql> ...

无痕的博客 485

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

基于linux c的mysql操作——幼儿园数据管理系统

上周对于mysql进行了简单的学习,利用c对mysql进行操作,主要用到了以下几个函数: mysql_init(); mysql_real_connect(数据库变量指针,网络地址,用户名,登录密码,目标数据库,0,NULL,0); mysql_query(数据库变量指针,SQL语句); MYSQL_RES *mysql_use_result(数据库变量指针); MYSQL_ROW...

weixin_30765319的博客 222

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Linux之mariadb数据库管理

linux之mariadb数据库管理 什么是数据库 数据库是指按照某些特定结构来存储数据资料的数据仓库。在当今这个大数据技术迅速崛起的年代,互联网上每天都会生成海量的数据信息,数据库技术也从最初只能存储简单的表格数据的单一集中存储模式,发展到了现如今存储海量数据的大型分布式模式。在信息化社会中,能够充分有效地管理和利用各种数据,挖掘其中的价值,是进行科学研究与决策管理的重要前提。同时,数据库技...

weixin_44828950的博客 237

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Linux系统中的数据库的管理

前言: 数据库(英文:Dtabase)就是一个存放数据的仓库,该仓库是按照 一定的数据结果来组织存储的,我们可以通过数据库的多种管理方式实现对数据 库的管理.今天我们将详细讲解一下Linux系统下数据库的管理. 数据管理系统的类形: 1、DB2 IBM:关系型数据库管理系统,在不同操作系统进行服务 2、Oracle 甲骨...

dghfttgv的博客 220

【Linux系统中的】数据库的管理

前言:                   数据库(英文:Dtabase)就是一个存放数据的仓库,该仓库是按照  一定的数据结果来组织存储的,我们可以通过数据库的多种管理方式实现对数据 库的管理.今天我们将详细讲解一下Linux系统下数据库的管理.               数据管理系统的类形: 1、DB2 IBM:关系型数据库管理系统,在不同操作系统进行服务 2、Oracle 甲骨...

weixin_43831670的博客 265

Linux下的MySQL数据库管理

Linux下的MySQL数据库管理 数据库就是数据的集合。 关系数据库是一种特殊的数据库,他将数据组织城标,并表示为表之间的关系。 数据库系统往往是大型项目的核心数据内容,如银行的用户账户信息,腾讯QQ的用户账户信息、股市的各种交易信息,以及各类网站用户注册信息等等都是以数据库方式保存。 复制代码 SQLServer –microsoft的关系数据库系统,运行在windows server服务器 ...

Brave Soul Blog 478

本地部署数据库管理工具 NocoDB 并实现外部访问(Linux 版本)

NocoDB 是一款基于开源技术的在线数据库管理工具,通过 WEB 界面将传统数据库转为在线表格,也可与 Webhook、第三方工具集成实现流程自动化。用户能够直观的像操作表格一样管理数据库,同时适合快速搭建数据管理系统。本文将详细的介绍如何利用 Docker 在本地部署 NocoDB 并结合路由侠实现外网访问本地部署的 NocoDB。‌。

zt1985q的博客 545

Linux下数据库的管理及基本操作

1.安装,开启服务 yum install mariadb-server -y systemctl start mariadb mysql_secure_installation ##第一次安装mysql以后通过这条命令可以对mysql进行设置 为了确保数据库的安全性和正常运转,需要先对数据库程序进行初始化操作。 这个初始化操作涉及下面6个步骤。【回车—>y—>输入密码,确认密码—...

qq_36016375的博客 5660

3.4 Linux中的数据库管理

数据库是存放数据的仓库,相当于一个高级的表格。我们常用到的数据库就是mysql的开源数据库,在linux中它的名称叫mariadb。 一、数据库初始化 dnf install mariadb-server ##安装mariadb systemctl enable --now mariadb mysql -u root ##未设置密码时登陆 netstat -antlup...

qq_45737059的博客 350

Linux进阶之数据库管理

MySQL 是一种流行的开源关系型数据库管理系统,适用于多种规模的应用。PostgreSQL 是一个功能强大的开源对象关系型数据库,支持复杂查询和事务处理。

K 1078

Linux下数据库mariaDB的管理

一、何为数据库? 数据库是以表格形式保存数据的特定结构。 支持通过基于表格结构的数据流的软件称为数据库管理系统(DBMS)。使用最广泛的数据库管理系(DBMS)是关系数据库管理系统(RDBMS)。数据库管理系统(DBMS)是一种计算机软件应用程序,可与终端用户,其他应用程序和数据库本身交互以捕获数据。通用数据库管理系统允许定义,创建,查询,更新和管理数据库。 数据库及其数据的功能是: 数据...

weixin_42566251的博客 644

Linux中mariadb数据库的管理

######1.用命令管理mariadb数据库###### ###1.安装mariadb并开启### ###2.安全初始化### 1.默认情况下,数据库的网络接口是开的,为了安全需要关闭此接口 1)查看网络接口 2)关闭网络接口 (写入第10行) 3)重启mariadb,查看接口是否关闭(无反馈就是关闭) 2.数据库的起始状态设定信息不安全,需要设定权限 ...

滴水穿石浅谈 606

Linux系统中的mariadb数据库管理

文章目录一、数据库介绍二、软件基本信息1. 安装2. 基本信息三、数据库的安全初始化1. 关闭数据库开放端口2.执行安全初始化脚本四、数据库的基本管理1. 查看2. 新建3. 更改4. 删除五、数据库密码管理1. 数据密码更改2. 数据库密码破解六、用户授权七、数据库的备份八、phpmyadmin 一、数据库介绍 二、软件基本信息 1. 安装 2. 基本信息 三、数据库的安全初始化 1. 关闭数据...

qq_45225437的博客 649

Linux中常用数据库管理系统之MariaDB

如今,市面上的数据库管理系统由很多种,如Mysql,Oracle,Postgres,MariaDB,不同的数据库管理系统在使用上会稍有差异,不过是大同小异,今天我们就以MariaDB为例,来了解下数据库管理系统是如何被使用的,若工作中使用的是其他数据库系统,只需快速查阅,了解其不同之处即可使用。我们生活在信息化时代,经常要跟数据打交道,它在我们的日常生活中无处不在,比如手机支付,微信聊天,淘宝购物,使用的这些在后台都会对应一个叫数据库的存在。翻译成中文就是数据库,是由一些数据表组成的数据源。

bingyu1024的博客 128

数据库管理-第355期 Linux4DB,配置检查与操作一览(20250808)

本期通过一张图,简单介绍了安装数据库的Linux操作系统需要检查、操作的配置内容。

yhw1809的博客 1017
上一篇: Linux系统之DNS的集群,更新(远程更新,加密更新)和ddns(动态域名解析)
下一篇: Linux之系统排错
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值