1. 程式人生 > >學習Linux筆記20170913

學習Linux筆記20170913

筆記

[[email protected] ~]# mysql -uroot

MariaDB [(none)]> SHOW DATABASES;

MariaDB [(none)]> QUIT

為數據庫賬號修改密碼:

mysqladmin [-u用戶名] [-p[舊密碼]] password ‘新密碼‘

導入/恢復到數據庫:

mysql [-u用戶名] [-p[密碼]] 數據庫名 < 備份文件.sql

為數據庫用戶授權/撤銷權限:

grant 權限1,權限2... on 庫名.表名 to 用戶名@客戶機地址 identified by ‘密碼‘;

revoke 權限1,權限2... on 庫名.表名 from 用戶名@客戶機地址;

表記錄增刪改查:

insert into [庫名.]表名 values(值1,值2,值3);

delete from [庫名.]表名 where ...;

update [庫名.]表名 set 字段名=字段值 where ....;

select 字段列表 from [庫名.]表名 where 字段名1=值 and|or 字段名2=值;

統計查詢結果的數量:

select count(*) from [庫名.]表名 where .. ..;

[[email protected] html]# mysql -uroot -p

Enter password:

MariaDB [(none)]>

MariaDB [(none)]> show databases; 查看當前服務器中有那些庫。

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

| Database |

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

| information_schema |

| bbsdb |

| mysql |

| performance_schema |

| test |

| ultrax |

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

6 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;

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]> describe user; 查看表的結構。

MariaDB [(none)]> use auth;

Database changed

MariaDB [auth]>

MariaDB [(none)]> use auth;

Database changed

MariaDB [auth]> create table users (user_name char(16) not null,user_passwd char(48) default ‘‘,primary key (user_name));

Query OK, 0 rows affected (0.09 sec)

MariaDB [auth]> show tables;

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

| Tables_in_auth |

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

| users |

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

1 row in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> desc users;

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

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

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

| user_name | char(16) | NO | PRI | NULL | |

| user_passwd | char(48) | YES | | | |

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

2 rows in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> desc auth.users;

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

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

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

| user_name | char(16) | NO | PRI | NULL | |

| user_passwd | char(48) | YES | | | |

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

2 rows in set (0.01 sec)

MariaDB [auth]> drop table auth.users;

MariaDB [auth]> show databases; 查看當前服務器中有哪些庫。

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

| Database |

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

| information_schema |

| auth |

| bbsdb |

| mysql |

| performance_schema |

| test |

| ultrax |

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

7 rows in set (0.00 sec)

MariaDB [auth]> drop database auth;

MariaDB [auth]> insert into users(user_name,user_passwd) values(‘zhangsan‘,password (‘123456‘));

Query OK, 1 row affected (0.03 sec)

MariaDB [auth]> insert into users values (‘lisi‘,password(‘654321‘));

Query OK, 1 row affected (0.04 sec)

MariaDB [auth]> select * from auth.users;

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

| user_name | user_passwd |

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

| lisi | *2A032F7C5BA932872F0F045E0CF6B53CF702F2C5 |

| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

2 rows in set (0.00 sec)

MariaDB [auth]> select user_name,user_passwd from auth.users where user_name=‘zhangsan‘;

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

| user_name | user_passwd |

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

| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

1 row in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> update auth.users set user_passwd=password(‘‘) where user_name=‘lisi‘;

Query OK, 1 row affected (0.06 sec)

Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [auth]> select * from auth.users;

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

| user_name | user_passwd |

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

| lisi | |

| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

2 rows in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> delete from auth.users where user_name=‘lisi‘;

Query OK, 1 row affected (0.04 sec)

MariaDB [auth]>

MariaDB [auth]> select * from auth.users;

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

| user_name | user_passwd |

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

| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

1 row in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> select user,host,password from mysql.user where user=‘‘;

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

| user | host | password |

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

| | localhost | |

| | localhost.localdomain | |

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

2 rows in set (0.00 sec)

MariaDB [auth]>

MariaDB [auth]> grant select on auth.* to ‘xiaoqi‘@‘localhost‘ identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

[[email protected] html]# mysql -u xiaoqi -p

Enter password:

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

Your MariaDB connection id is 16

Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]>

MariaDB [(none)]> select * from auth.users;

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

| user_name | user_passwd |

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

| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

1 row in set (0.00 sec)

MariaDB [(none)]> select * from mysql.user;

ERROR 1142 (42000): SELECT command denied to user ‘xiaoqi‘@‘localhost‘ for table ‘user‘

MariaDB [(none)]>

MariaDB [(none)]> create database bdqn;

Query OK, 1 row affected (0.00 sec)

授予權限。

MariaDB [(none)]> grant all on bdqn.* to ‘dbuser‘@‘192.168.4.19‘ identified by ‘[email protected]‘;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> show grants for ‘dbuser‘@‘192.168.4.19‘;查看權限

MariaDB [(none)]> revoke all on auth.* from ‘xiaoqi‘@‘localhost‘;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

備份數據庫。

[[email protected] beifen]# mysqldump -u root -p mysql user > mysql-user.sql

[[email protected] beifen]# mysqldump -u root -p --database auth > auth.sql

[[email protected] beifen]# mysqldump -u root -p --opt --all-databases > all-data.sql

[[email protected] beifen]# cat mysql-user.sql

[[email protected] beifen]# grep -v ‘^--‘ auth.sql | grep -v ‘^/‘ | grep -v ‘^$‘

恢復數據庫

[[email protected] beifen]# mysql -u root -p test < mysql-user.sql

Enter password:

[[email protected] beifen]# mysql -u root -p

Enter password:

MariaDB [(none)]>

MariaDB [(none)]> use test;

MariaDB [test]> show tables;

[[email protected] beifen]# mysql -u root -p < ./all-data.sql

[[email protected] beifen]# mysql -u root -p

MariaDB [(none)]> show databases;

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

| Database |

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

| information_schema |

| auth |

| bbsdb |

| bdqn |

| mysql |

| performance_schema |

| test |

| ultrax |

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

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

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

[[email protected] ~]# yum -y install httpd mariadb-server mariadb php php-mysql

2.配置MySQL

[[email protected] ~]# systemctl restart mariadb

[[email protected] ~]# systemctl enable mariadb.service

[[email protected] ~]# mysqladmin -u root password ‘Taren1‘

3.配置Httpd

[[email protected] ~]# vim /var/www/html/test1.php

<?php

phpinfo();

?>

[[email protected] ~]# vim /var/www/html/test2.php

<?php

$link=mysql_connect(‘localhost‘,‘root‘,‘Taren1‘);

if($link) echo "Success !!"; //成功則顯示Success !!

else echo "Failure !!"; //失敗則顯示Failure !!

mysql_close(); //關閉數據庫連接

?>

5.啟動服務

[[email protected] ~]# systemctl start httpd.service

6.測試

[[email protected] ~]# firefox http://127.0.0.1/test1.php

[[email protected] ~]# firefox http://127.0.0.1/test2.php

[[email protected] ~]# systemctl restart httpd.service

實驗五:PHP應用部署(Discuz!論壇系統)

1.建論壇庫

[[email protected] ~]# mysql -uroot -p

Enter password: //驗證管理密碼

mysql> create database bbsdb; //創建bbsdb數據庫

mysql> show databases; //查看數據庫

mysql> grant all on bbsdb.* to [email protected] identified by ‘pwd123‘; //授權數據庫

mysql> quit

2.部署論壇網頁代碼

[[email protected] ~]# unzip Discuz_X3.4_SC_UTF8.zip

[[email protected] ~]# ls upload/

[[email protected] ~]# cp -rf upload/* /var/www/html/

[[email protected] ~]# cd /var/www/html/

[[email protected] ~]# chown -R apache template/ config/ data/ uc_client/ uc_server/

selinux安全機制。

[[email protected] html]# getenforce

Enforcing

[[email protected] html]# setenforce 0

[[email protected] html]# ls

[[email protected] html]# getenforce

Permissive

3.安裝論壇系統

[[email protected] ~]# firefox http://127.0.0.1/

4.訪問論壇前臺首頁 http://127.0.0.1/


微信 269611002 一起交流吧


本文出自 “龐承德” 博客,請務必保留此出處http://20214843.blog.51cto.com/13387457/1971868

學習Linux筆記20170913