学习Linux笔记20170913

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学习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 一起交流吧


以上是关于学习Linux笔记20170913的主要内容,如果未能解决你的问题,请参考以下文章

20170913-构建之法:现代软件工程-阅读笔记

20170913-构建之法:现代软件工程-阅读笔记

《20170913-构建之法:现代软件工程-阅读笔记》

linux学习笔记二

linux学习笔记一

Linux学习笔记