[Email protected] ~]# Mysql-uroot
MariaDB [(None)]> SHOW DATABASES;
MariaDB [(none)]> QUIT
To change the password for the database account:
mysqladmin [-u user name] [-p[old password]] password ' new password '
Import/Restore to database:
MySQL [-u user name] [-p[password]] Database name < backup file. sql
Authorize/revoke permissions for database users:
Grant permissions 1, permissions 2 ... on the Library name. Table name to User name @ Client address identified by ' password ';
Revoke permissions 1, permissions 2 ... on the Library name. Table name from user name @ client address;
Table record additions and deletions:
insert into [library name.] Table name values (value 1, value 2, value 3);
Delete from [library name.] Table name where ...;
Update [library name.] Table name Set field name = field value where ...;
Select field list from [library name.] Table name where field name 1= value And|or field name 2= value;
Number of statistics Query results:
Select COUNT (*) from [library name.] Table name where: ..;
[Email protected] html]# mysql-uroot-p
Enter Password:
MariaDB [(None)]>
MariaDB [(None)]> show databases; See which libraries are in the current server.
+--------------------+
| Database |
+--------------------+
| Information_schema |
| Bbsdb |
| MySQL |
| Performance_schema |
| Test |
| Ultrax |
+--------------------+
6 rows in Set (0.00 sec)
MariaDB [(none)]> use MySQL;
MariaDB [mysql]> Show tables; View which tables are in the currently used library.
+---------------------------+
| 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 |
+---------------------------+
Rows in Set (0.00 sec)
MariaDB [mysql]> describe user; View the structure of the table.
MariaDB [(none)]> use auth;
Database changed
MariaDB [auth]>
MariaDB [(none)]> use auth;
Database changed
MariaDB [auth]> CREATE TABLE users (user_name char (not null,user_passwd char) 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; View which libraries are in the current server.
+--------------------+
| 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), 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)
Grant permissions.
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 '; View permissions
MariaDB [(none)]> revoke all on auth.* from ' xiaoqi ' @ ' localhost ';
Query OK, 0 rows Affected (0.00 sec)
MariaDB [(None)]>
Back up the database.
[[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 ' ^$ '
Recovering a Database
[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. Configure MySQL
[Email protected] ~]# systemctl restart MARIADB
[Email protected] ~]# Systemctl enable Mariadb.service
[Email protected] ~]# mysqladmin-u root password ' Taren1 '
3. Configure 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 shows success!!
else echo "Failure!"; Failure will show failure!!
Mysql_close (); To close a database connection
?>
5. Start the service
[Email protected] ~]# systemctl start Httpd.service
6. Testing
[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
Experiment Five: PHP application Deployment (discuz! Forum system)
1. Building a forum Library
[Email protected] ~]# mysql-uroot-p
Enter Password: //Verify admin password
mysql> CREATE DATABASE Bbsdb; //Create BBSDB Database
mysql> show databases; //View Database
Mysql> Grant all on bbsdb.* to [e-mail protected] identified by ' pwd123 '; //Authorization database
Mysql> quit
2. Deploy Forum page code
[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 security mechanism.
[Email protected] html]# Getenforce
Enforcing
[Email protected] html]# Setenforce 0
[[email protected] html]# ls
[Email protected] html]# Getenforce
Permissive
3. Install the Forum system
[email protected] ~]# Firefox HTTP://127.0.0.1/
4. Visit the Forum front page HTTP://127.0.0.1/
2,696,110,021 exchanges.
Learn Linux notes 20170913