当前位置:Gxlcms > 数据库问题 > mariadb

mariadb

时间:2021-07-01 10:21:17 帮助过:16人阅读

 

 

数据库环境的配置

[root@localhost ~]# yum install mariadb-server -y  ##数据库软件的下载

Loaded plugins: langpacks

Resolving Dependencies

--> Running transaction check

---> Package mariadb-server.x86_64 1:5.5.35-3.el7 will be installed

--> Processing Dependency: mariadb(x86-64) = 1:5.5.35-3.el7 for package: 1:mariadb-server-5.5.35-3.el7.x86_64

--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.35-3.el7.x86_64

--> Processing Dependency: perl(Data::Dumper) for package: 1:mariadb-server-5.5.35-3.el7.x86_64

--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.35-3.el7.x86_64

--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.35-3.el7.x86_64

--> Running transaction check

---> Package mariadb.x86_64 1:5.5.35-3.el7 will be installed

---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed

---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed

--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64

--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64

---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed

--> Running transaction check

---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed

--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch

--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch

--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch

--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch

--> Running transaction check

---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed

--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch

--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch

---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed

--> Running transaction check

---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed

---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=====================================================================

 Package                  Arch    Version            Repository

                                                                Size

=====================================================================

Installing:

 mariadb-server           x86_64  1:5.5.35-3.el7     rhel_dvd   11 M

Installing for dependencies:

 mariadb                  x86_64  1:5.5.35-3.el7     rhel_dvd  8.9 M

 perl-Compress-Raw-Bzip2  x86_64  2.061-3.el7        rhel_dvd   32 k

 perl-Compress-Raw-Zlib   x86_64  1:2.061-4.el7      rhel_dvd   57 k

 perl-DBD-MySQL           x86_64  4.023-5.el7        rhel_dvd  140 k

 perl-DBI                 x86_64  1.627-4.el7        rhel_dvd  802 k

 perl-Data-Dumper         x86_64  2.145-3.el7        rhel_dvd   47 k

 perl-IO-Compress         noarch  2.061-2.el7        rhel_dvd  260 k

 perl-Net-Daemon          noarch  0.48-5.el7         rhel_dvd   51 k

 perl-PlRPC               noarch  0.2020-14.el7      rhel_dvd   36 k

 

Transaction Summary

=====================================================================

Install  1 Package (+9 Dependent packages)

 

Total download size: 21 M

Installed size: 107 M

Downloading packages:

(1/10): mariadb-5.5.35-3.el7.x86_64.rpm         | 8.9 MB   00:01     

(2/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86 |  32 kB   00:00     

(3/10): mariadb-server-5.5.35-3.el7.x86_64.rpm  |  11 MB   00:01     

(4/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_ |  57 kB   00:00     

(5/10): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm   | 140 kB   00:00     

(6/10): perl-Data-Dumper-2.145-3.el7.x86_64.rpm |  47 kB   00:00     

(7/10): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB   00:00     

(8/10): perl-DBI-1.627-4.el7.x86_64.rpm         | 802 kB   00:00     

(9/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm   |  51 kB   00:00     

(10/10): perl-PlRPC-0.2020-14.el7.noarch.rpm    |  36 kB   00:00     

---------------------------------------------------------------------

Total                                    10 MB/s |  21 MB  00:02     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : perl-Data-Dumper-2.145-3.el7.x86_64              1/10

  Installing : 1:mariadb-5.5.35-3.el7.x86_64                    2/10

  Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64      3/10

  Installing : perl-Net-Daemon-0.48-5.el7.noarch                4/10

  Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64       5/10

  Installing : perl-IO-Compress-2.061-2.el7.noarch              6/10

  Installing : perl-PlRPC-0.2020-14.el7.noarch                  7/10

  Installing : perl-DBI-1.627-4.el7.x86_64                      8/10

  Installing : perl-DBD-MySQL-4.023-5.el7.x86_64                9/10

  Installing : 1:mariadb-server-5.5.35-3.el7.x86_64            10/10

  Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64       1/10

  Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                2/10

  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64              3/10

  Verifying  : perl-PlRPC-0.2020-14.el7.noarch                  4/10

  Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64      5/10

  Verifying  : 1:mariadb-server-5.5.35-3.el7.x86_64             6/10

  Verifying  : perl-DBI-1.627-4.el7.x86_64                      7/10

  Verifying  : 1:mariadb-5.5.35-3.el7.x86_64                    8/10

  Verifying  : perl-DBD-MySQL-4.023-5.el7.x86_64                9/10

  Verifying  : perl-IO-Compress-2.061-2.el7.noarch             10/10

 

Installed:

  mariadb-server.x86_64 1:5.5.35-3.el7                               

 

Dependency Installed:

  mariadb.x86_64 1:5.5.35-3.el7                                      

  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7                       

  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7                        

  perl-DBD-MySQL.x86_64 0:4.023-5.el7                                

  perl-DBI.x86_64 0:1.627-4.el7                                      

  perl-Data-Dumper.x86_64 0:2.145-3.el7                              

  perl-IO-Compress.noarch 0:2.061-2.el7                              

  perl-Net-Daemon.noarch 0:0.48-5.el7                                

  perl-PlRPC.noarch 0:0.2020-14.el7                                  

 

Complete!

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0  

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# netstat -antlpe | grep mysql

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      27         55211      4303/mysqld         

 

[root@localhost ~]# vim /etc/my.cnf  ##数据库本身配置文件

 

@@@@@

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0    

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

skip-networking=1    ##关闭数据库在网络打开的端口

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

 

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

~                                                                    

~                                                                    

~                                                                    

@@@@@@                     

 

[root@localhost ~]# systemctl restart mariadb  

[root@localhost ~]# netstat -antlpe | grep mysql  ##查看打开的端口

[root@localhost ~]# mysql   ##进入数据库

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

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

 

MariaDB [(none)]> exit

Bye

[root@localhost ~]# mysql_secure_installation   ##更改登陆设置

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

 

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  ##不允许root远程登陆

 ... 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!

[root@localhost ~]# mysql  ##再次进入数据库

ERROR 1045 (28000): Access denied for user   ##访问被拒 ‘root‘@‘localhost‘ (using password: NO)

[root@localhost ~]# mysql -uroot -pwestos ##使用账户密码登陆(但此登陆方式密码会被记录。不安全)

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 12

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

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

 

MariaDB [(none)]> exit

Bye

[root@localhost ~]# mysql -uroot -p

Enter password:     ##用户登陆,密码无回显,更安全

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 13

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

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

 

MariaDB [(none)]> exit

Bye

[root@localhost ~]#

 

 

 

1.登陆 mysql -uroot -p

[root@localhost ~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

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

 

2.查询

*show databases;   ##显示数据库(同ls)

*use mysql;      ##进入mysql数据库(同cd)

*select * from user;   ##查询表中内容(同show)

* desc user;  ##显示表结构(显示所有字段的名称)

MariaDB [(none)]> show databases;  ##显示数据库

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 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                      |

+---------------------------+

24 rows in set (0.00 sec)

 

MariaDB [mysql]> select * from user;   ##查询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 | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | 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 | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | 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 | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | 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 |        |                       |

+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+

3 rows in set (0.00 sec)

 

MariaDB [mysql]> select Host,User,Password from user;

+-----------+------+-------------------------------------------+

| Host      | User | Password                                  |

+-----------+------+-------------------------------------------+

| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |

| 127.0.0.1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |

| ::1       | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |

+-----------+------+-------------------------------------------+

3 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‘)   &n

人气教程排行