數據庫 二


數據庫

 

[root@server-dns ~]# systemctl stop firewalld.service

[root@server-dns ~]# yum install mariadb-server -y

Loaded plugins: langpacks

rhel_dvd                                                 | 4.1 kB     00:00     

Resolving Dependencies

--> Running transaction check

 

[root@server-dns ~]# systemctl start mariadb

 

此時沒有密碼,可直接登陸

[root@server-dns ~]# mysql -uroot

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)]>

 

[root@server-dns ~]# vim /etc/my.cnf

 10 skip-networking=1

[root@server-dns ~]# systemctl restart mariadb

 

添加密碼

[root@server-dns ~]# 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): ##空格(默認選項)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

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] ##空格(默認選項)

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] ##空格(默認選項)

 ... 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] ##空格(默認選項)

 ... 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]  ##空格(默認選項)

 - 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] ##空格(默認選項)

 ... 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@server-dns ~]# mysql -uroot -p123

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

Your MariaDB connection id is 11

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)]>

或者

[root@server-dns ~]# mysql -uroot -p

Enter password:

 

 

MariaDB [(none)]> SHOW DATABASES; ##查看已有的數據庫,分號結尾

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

3 rows in set (0.00 sec)

 

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]> SHOW TABLES; ##顯示庫中的表

MariaDB [mysql]> DESC user; ##查看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 USER,HOST,PASSWORD from user; ##查詢user表中的USER,HOST,PASSWORD

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

| USER | HOST      | PASSWORD                                  |

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

| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

| root | 127.0.0.1 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

| root | ::1       | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

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

 

MariaDB [(none)]> CREATE DATABASE hello; ##創建hello數據庫

Query OK, 1 row affected (0.00 sec)

 

MariaDB [(none)]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| hello              |

| mysql              |

| performance_schema |

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

MariaDB [hello]> CREATE TABLE westos(username varchar(15) not null,password varchar(15) not null); ##創建westos表,設定username,password的字段

Query OK, 0 rows affected (0.06 sec)

 

MariaDB [hello]> SHOW TABLES;

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

| Tables_in_hello |

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

| westos          |

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

1 row in set (0.00 sec)

 

MariaDB [hello]> DESC westos;

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

| Field    | Type        | Null | Key | Default | Extra |

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

| username | varchar(15) | NO   |     | NULL    |       |

| password | varchar(15) | NO   |     | NULL    |       |

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

 

MariaDB [hello]> INSERT INTO westos VALUES ('lee','123'); ##在westos表中添加數據

Query OK, 1 row affected (0.04 sec)

 

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 123      |

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

1 row in set (0.00 sec)

 

 

MariaDB [hello]> UPDATE westos set password='234'; ##將westos表中的password改爲234

Query OK, 2 rows affected (0.35 sec)

Rows matched: 2  Changed: 2  Warnings: 0

 

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 234      |

| yz       | 234      |

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

2 rows in set (0.00 sec)

 

MariaDB [hello]> UPDATE westos set password='345' WHERE username='yz';

Query OK, 1 row affected (0.03 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 234      |

| yz       | 345      |

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

2 rows in set (0.00 sec) ##將westos表中username爲yz的password改爲345

 

MariaDB [hello]> DELETE FROM westos WHERE username='lee';

Query OK, 1 row affected (0.35 sec)

 

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| yz       | 345      |

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

1 row in set (0.00 sec) ##刪除westos表中username爲lee的用戶的所有信息

 

[root@server-dns ~]# mysqldump -uroot -p123 hello > /mnt/hello.sql ##保存hello庫中的數據到/mnt/hello.sql

 

MariaDB [hello]> DROP table westos; ##刪除hello庫中的westos表

Query OK, 0 rows affected (0.04 sec)

MariaDB [hello]> DROP database hello; ##刪除數據庫hello

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)

 

[root@server-dns ~]# mysql -uroot -p123 -e "CREATE DATABASE hello;" ##創建hello庫

[root@server-dns ~]# mysql -uroot -p123 hello < /mnt/hello.sql ##將/mnt/hello.sql的數據導入到hello庫中

[root@server-dns ~]# mysql -uroot -p123 -e "select * from hello.westos;"

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

| username | password |

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

| yz       | 345      |

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

[root@server-dns ~]#

 

MariaDB [(none)]> CREATE USER hello@'localhost' identified by 'hello';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> GRANT SELECT on hello.* TO hello@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SHOW GRANTS FOR hello@localhost;

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

| Grants for hello@localhost                                                                                   |

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

| GRANT USAGE ON *.* TO 'hello'@'localhost' IDENTIFIED BY PASSWORD '*6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119' |

| GRANT SELECT ON `hello`.* TO 'hello'@'localhost'                                                             |

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

 

MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DELETE on hello.* TO hello@localhost

    -> ;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SHOW GRANTS FOR hello@localhost;+--------------------------------------------------------------------------------------------------------------+

| Grants for hello@localhost                                                                                   |

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

| GRANT USAGE ON *.* TO 'hello'@'localhost' IDENTIFIED BY PASSWORD '*6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119' |

| GRANT SELECT, INSERT, UPDATE, DELETE ON `hello`.* TO 'hello'@'localhost'                                     |

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

2 rows in set (0.00 sec)

 

[root@server-dns ~]# mysqladmin -uroot -p123 password hello ##修改登陸密碼

[root@server-dns ~]# mysql -uroot -p

Enter password:

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

Your MariaDB connection id is 24

Server version: 5.5.35-MariaDB MariaDB Server

 

忘記密碼

[root@server-dns ~]# systemctl stop mariadb.service

[root@server-dns ~]# mysqld_safe --skip-grant-tables&

[1] 5917

[root@server-dns ~]# 161207 23:09:04 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

161207 23:09:04 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

 

MariaDB [(none)]> UPDATE mysql.user set Password=password('hello') WHERE User='root';

Query OK, 3 rows affected (0.33 sec)

Rows matched: 3  Changed: 3  Warnings: 0

 

MariaDB [(none)]> quit

 

[root@server-dns ~]# fg

mysqld_safe --skip-grant-tables

^Z

[1]+  Stopped                 mysqld_safe --skip-grant-tables

[root@server-dns ~]#

[root@server-dns ~]# ps aux | grep mysql

root      5917  0.0  0.0 113252  1552 pts/0    T    23:09   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables

mysql     6072  0.1  4.7 859056 90368 pts/0    Sl   23:09   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      6182  0.0  0.0 112640   936 pts/0    S+   23:12   0:00 grep --color=auto mysql

[root@server-dns ~]# kill -9 6072

[root@server-dns ~]# systemctl start mariadb

 

[root@server-dns ~]# yum install httpd -y

下載phpMyAdmain-3.4.0-all-languages.tar.bz2

[root@server-dns html]# tar jxf phpMyAdmain-3.4.0-all-languages.tar.bz2

[root@server-dns html]# mv phpMyAdmain-3.4.0-all-languages saozhu

[root@server-dns html]# cd saozhu/

[root@server-dns saozhu]# cp -p config.sample.inc.php config.inc.php

[root@server-dns saozhu]# vim config.inc.php

17 $cfg['blowfish_secret'] = 'westos'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH    ! */

 

[root@server-dns saozhu]# systemctl stop firewalld.service

[root@server-dns saozhu]# systemctl start httpd

[root@server-dns saozhu]# yum install php -y

 wKiom1hJMerTjZfNAAHw7KzL2fk561.png-wh_50

wKiom1hJMevT7z3_AAKFx1yuc9I042.png-wh_50


[root@server-dns ~]# mysql -uroot -phello -e "select * from saozhu.vuser;"

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

| username         | password | domain     | maildir           |

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

| [email protected] | 123      | westos.org | westos.org/admin/ |

| [email protected]   | 123      | redhat.org | westos.org/lee/   |

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


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