[root@localhost yum.repos.d]# yum install mariadb-server -y #下载数据库软件
Loaded plugins: langpacks
rhel_dvd | 4.1 kB 00:00
(1/2): rhel_dvd/group_gz | 134 kB 00:00
(2/2): rhel_dvd/primary_db | 3.4 MB 00:00
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
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mariadb-server x86_64 1:5.5.35-3.el7 rhel_dvd
perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
[root@localhost yum.repos.d]# systemctl start mariadb #开启数据库服务
[root@localhost yum.repos.d]# 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)]> quit #退出
Bye
[root@localhost yum.repos.d]# mysql -uroot -h172.25.254.126 #匿名登陆
ERROR 1130 (HY000): Host '172.25.254.126' is not allowed to connect to this MariaDB server
[root@localhost yum.repos.d]# netstat -antlpe | grep mysql
#列出数据库的工作端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 64253 2635/mysqld
[root@localhost yum.repos.d]# 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 yum.repos.d]# systemctl restart mariadb #重启服务
[root@localhost yum.repos.d]# netstat -antlpe | grep mysql
#查看端口,此时端口关闭
[root@localhost yum.repos.d]# 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 #为root设置密码
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] #禁止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] #删除测试数据库并访问
- 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@localhost yum.repos.d]# mysql -uroot #root登陆
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost yum.repos.d]# mysql -uroot -p #root密码登陆
Enter password:
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)]> quit
Bye
[root@localhost yum.repos.d]# mysql #此时本地的登陆也需密码
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# mysql -uroot -p #登陆
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
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)]> SHOW DATABASES; #显示库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [mysql]> USE mysql; #使用mysql目录
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表格内容。
-> SELECT * FROM user ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT * FROM user' at line 2
MariaDB [mysql]> SELECT * FROM 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 User,Host,Password FROM user;
#列出user表格中User,Host,Password字段内容。(这里的字段指的是我们常说的列)
+------+-----------+-------------------------------------------+
| User | Host | Password |
+------+-----------+-------------------------------------------+
| root | localhost | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| root | 127.0.0.1 | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| root | ::1 | *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') | 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 Where User='root' AND Host='localhost';
#列出表格user中User字段为'root' ,Host字段为为'localhost',的User,Host,Password三个字段内容。
+------+-----------+-------------------------------------------+
| User | Host | Password |
+------+-----------+-------------------------------------------+
| root | localhost | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)
MariaDB [mysql]>quit
Bye
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
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)]> CREATE DATABASE westos; #新建一个westos库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| westos |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> USE westos; #使用westos
Database changed
MariaDB [westos]> SHOW TABLES;
Empty set (0.00 sec) #此时没有
MariaDB [westos]> CREATE TABLE linux(
-> username varchar(6) not null,
-> password varchar(8) not null);
#新建一个linux表格,varchar为可变字符,()内为其最长长度,not null指不能为空
Query OK, 0 rows affected (0.06 sec)
MariaDB [westos]> SHOW TABLES; #查看表格
+------------------+
| Tables_in_westos |
+------------------+
| linux |
+------------------+
1 row in set (0.00 sec)
MariaDB [westos]> DESC linux; #查看表格属性
+----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+-------+
| username | varchar(6) | NO | | NULL | |
| password | varchar(8) | NO | | NULL | |
+----------+------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
MariaDB [westos]> INSERT INTO Linux values ('zhang','123'); #在表格中添加内容
ERROR 1146 (42S02): Table 'westos.Linux' doesn't exist
MariaDB [westos]> INSERT INTO linux values ('zhangs','123');
Query OK, 1 row affected (0.04 sec)
MariaDB [westos]> INSERT INTO linux values ('zhangsan','123');
Query OK, 1 row affected, 1 warning (0.03 sec)
#'zhangsan'超过6,不可添加
MariaDB [westos]> INSERT INTO linux values ('lee','123');
Query OK, 1 row affected (0.01 sec)
MariaDB [westos]> SELECT * FROM linux;
+----------+----------+
| username | password |
+----------+----------+
| zhang | 123 |
| zhangs | 123 |
| lee | 123 |
+----------+----------+
3 rows in set (0.00 sec)
MariaDB [westos]> quit
Bye
[root@localhost ~]# cd /var/lib/mysql/ #此目录为数据库存放目录
[root@localhost mysql]# ls
aria_log.00000001 ibdata1 ib_logfile1 mysql.sock westos
aria_log_control ib_logfile0 mysql performance_schema
[root@localhost mysql]# cd westos/
[root@localhost westos]# ls
db.opt linux.frm
[root@localhost westos]# file linux.frm #表格不能查看,其类型不支持
linux.frm: MySQL table definition file Version 10
[root@localhost westos]# cd ..
[root@localhost mysql]# mv westos hello #将westos数据库改为hello
[root@localhost mysql]# ls
aria_log.00000001 hello ib_logfile0 mysql performance_schema
aria_log_control ibdata1 ib_logfile1 mysql.sock
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
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)]> SHOW DATABASES; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| hello | #修改成功
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> QUIT
Bye
[root@localhost mysql]# mv hello/ westos #重新修改回来
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 21
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)]> FLUSH PRIVILEGES; #刷新列表
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> USE westos; #使用westos数据库
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 [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| linux |
+------------------+
1 row in set (0.00 sec)
MariaDB [westos]> ALTER TABLE linux RENAME message; #重新命名Linux表格
Query OK, 0 rows affected (0.01 sec)
MariaDB [westos]> SHOW TABLES;
+------------------+
| Tables_in_westos |
+------------------+
| message |
+------------------+
1 row in set (0.00 sec)
MariaDB [westos]> SELECT * FROM message;
+----------+----------+
| username | password |
+----------+----------+
| zhang | 123 |
| zhangs | 123 |
| lee | 123 |
+----------+----------+
3 rows in set (0.00 sec)
MariaDB [westos]> ALTER TABLE message ADD age varchar(4); #添加age字段,默认添加在最后面
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [westos]> SELECT * FROM message;
+----------+----------+------+
| username | password | age |
+----------+----------+------+
| zhang | 123 | NULL |
| zhangs | 123 | NULL |
| lee | 123 | NULL |
+----------+----------+------+
3 rows in set (0.00 sec)
MariaDB [westos]> ALTER TABLE message DROP age; #删除age字段
Query OK, 3 rows affected (0.13 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [westos]> SELECT * FROM message;
+----------+----------+
| username | password |
+----------+----------+
| zhang | 123 | #已删除
| zhangs | 123 |
| lee | 123 |
+----------+----------+
3 rows in set (0.00 sec)
MariaDB [westos]> ALTER TABLE message ADD age varchar(4) AFTER username;
#在username字段后面添加age字段,注意默认字段添加不能添加在最前面。
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [westos]> SELECT * FROM message;
+----------+------+----------+
| username | age | password |
+----------+------+----------+
| zhang | NULL | 123 |
| zhangs | NULL | 123 |
| lee | NULL | 123 |
+----------+------+----------+
3 rows in set (0.01 sec)
MariaDB [westos]> UPDATE message SET username='lilei' WHERE username='zhang';
#修改表格内容,zahng--->lilei
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [westos]> SELECT * FROM message;
+----------+------+----------+
| username | age | password |
+----------+------+----------+
| lilei | NULL | 123 |
| zhangs | NULL | 123 |
| lee | NULL | 123 |
+----------+------+----------+
3 rows in set (0.00 sec)
MariaDB [westos]> DELETE FROM message WHERE username='lilei'; #删除lilei一行内容
Query OK, 1 row affected (0.07 sec)
MariaDB [westos]> SELECT * FROM message;
+----------+------+----------+
| username | age | password |
+----------+------+----------+
| zhangs | NULL | 123 | #已删除
| lee | NULL | 123 |
+----------+------+----------+
2 rows in set (0.00 sec)
MariaDB [westos]> DROP TABLE message; #删除message表格
Query OK, 0 rows affected (0.02 sec)
MariaDB [westos]> SELECT * FROM message;
ERROR 1146 (42S02): Table 'westos.message' doesn't exist #已删除
MariaDB [westos]> DROP DATABASE westos; #删除westos数据库
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)
MariaDB [(none)]>
[root@localhost ~]# yum install httpd php -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64
mailcap.noarch 0:2.1.41-2.el7 php-cli.x86_64 0:5.4.16-21.el7
php-common.x86_64 0:5.4.16-21.el7
Complete!
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# lftp 172.25.254.250
lftp 172.25.254.250:~> cd pub/docs/software/
l
lftp172.25.254.250:/pub/docs/software>getphpMyAdmin-3.4.0-all-languages.tar.bz2
4548030 bytes transferred
lftp 172.25.254.250:/pub/docs/software> quit
[root@localhost html]# ls
phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@localhost html]#tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@localhost html]# ls
phpMyAdmin-3.4.0-all-languages phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@localhost html]# rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@localhost html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
[root@localhost html]# cd mysqladmin/
[root@localhost mysqladmin]# ls
browse_foreigners.php main.php server_status.php
bs_disp_as_mime_type.php navigation.php server_synchronize.php
bs_play_media.php phpdoctor.ini server_variables.php
ChangeLog phpinfo.php setup
changelog.php phpmyadmin.css.php show_config_errors.php
chk_rel.php pmd sql.php
config.sample.inc.php pmd_common.php tbl_addfield.php
contrib pmd_display_field.php tbl_alter.php
CREDITS pmd_general.php tbl_change.php
db_create.php pmd_help.php tbl_chart.php
db_datadict.php pmd_pdf.php tbl_create.php
db_export.php pmd_relation_new.php tbl_export.php
db_import.php pmd_relation_upd.php tbl_get_field.php
db_operations.php pmd_save_pos.php tbl_import.php
db_printview.php prefs_forms.php tbl_indexes.php
db_qbe.php prefs_manage.php tbl_move_copy.php
db_search.php print.css tbl_operations.php
db_sql.php querywindow.php tbl_printview.php
db_structure.php README tbl_relation.php
db_tracking.php README.VENDOR tbl_replace.php
docs.css RELEASE-DATE-3.4.0 tbl_row_action.php
Documentation.html robots.txt tbl_select.php
Documentation.txt schema_edit.php tbl_sql.php
enum_editor.php schema_export.php tbl_structure.php
export.php scripts tbl_tracking.php
favicon.ico server_binlog.php themes
import.php server_collations.php themes.php
import_status.php server_databases.php TODO
index.php server_engines.php transformation_overview.php
INSTALL server_export.php transformation_wrapper.php
js server_import.php url.php
libraries server_privileges.php user_password.php
LICENSE server_processlist.php view_create.php
license.php server_replication.php view_operations.php
locale server_sql.php webapp.php
[root@localhost mysqladmin]# cp config.sample.inc.php config.inc.php
[root@localhost mysqladmin]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
libxml
mhash
openssl
pcntl
pcre
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zip
zlib
[Zend Modules]
[root@localhost mysqladmin]# yum install php-mysql.x86_64
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
php-pdo.x86_64 0:5.4.16-21.el7
Complete!
[root@localhost mysqladmin]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
libxml
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
xml
zip
zlib
[Zend Modules]
[root@localhost mysqladmin]# systemctl restart httpd
MariaDB [(none)]> CREATE USER yifan@'localhost' identified by 'westos';
#建立一个用户,'localhost'只仅允许在本地的登陆,密码为'westos',此时用户仅允许登陆,不能做任何事;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT SELECT on westos.* to yifan@localhost;
Query OK, 0 rows affected (0.00 sec)
#为用户添加查看权限
MariaDB [(none)]> GRANT UPDATE on westos.* to yifan@localhost;
Query OK, 0 rows affected (0.00 sec)
#为用户添加修改表格内容,注意此功能只可以修改,不能添加。
MariaDB [(none)]> SHOW GRANTS FOR yifan@localhost;
#查看用户授予被功能。
+--------------------------------------------------------------------------------------------------------------+
| Grants for yifan@localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'yifan'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |
| GRANT SELECT, UPDATE ON `westos`.* TO 'yifan'@'localhost' |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> REVOKE UPDATE,SELECT on westos.* FROM yifan@localhost;
Query OK, 0 rows affected (0.00 sec)
#删除用户‘UPDATE,SELECT’功能。
MariaDB [(none)]> DROP USER yifan@localhost;
Query OK, 0 rows affected (0.00 sec)
#删除yifan@localhost用户。
超级用户密码忘记
[root@localhost mysqladmin]# systemctl stop mariadb.service #关闭数据库
[root@localhost mysqladmin]# mysqld_safe --skip-grant-tables &
[1] 7683
#跳过用户授权表开启数据库,并打入后台。
[root@localhost mysqladmin]# 180526 02:43:29 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
180526 02:43:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost mysqladmin]# mysql #进入数据库
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
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)]> UPDATE mysql.user SET Password=password('123') WHERE User='root';
#将root密码改为“123”,password('123')代表加密储存。
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
MariaDB [(none)]> quit
Bye
[root@localhost mysqladmin]# fg #调回前台
mysqld_safe --skip-grant-tables
^C^C^C^Z #此时无法跳出,用ctrl+z结束。
[1]+ Stopped mysqld_safe --skip-grant-tables
mysql_safe: no process found
[root@localhost mysqladmin]# killall -9 mysqld_safe
[1]+ Killed mysqld_safe --skip-grant-tables
[root@localhost mysqladmin]# ps aux | grep mysql
mysql 7838 0.0 9.3 859068 90616 pts/1 Sl 02:43 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 7899 0.0 0.0 112640 936 pts/1 R+ 02:47 0:00 grep --color=auto mysql
[root@localhost mysqladmin]# kill -9 7838
[root@localhost mysqladmin]# ps aux | grep mysql
root 7902 0.0 0.0 112640 936 pts/1 R+ 02:48 0:00 grep --color=auto mysql
[root@localhost mysqladmin]# systemctl start mariadb.service
[root@localhost mysqladmin]# mysql -uroot -p123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
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)]> quit
Bye
###修改密码#####
[root@localhost mysqladmin]# mysqladmin -uroot -p123 password '321'
[root@localhost mysqladmin]# mysql -uroot -p123
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost mysqladmin]# mysql -uroot -p321
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
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)]> quit
Bye
备份所有表格
[root@localhost mysqladmin]# mysqldump -uroot -p321 --all-database
#备份所有数据库到当前目录。
[root@localhost mysqladmin]#mysqldump -uroot -p321--all-database --no-data
#备份所有数据库的框架,不备份里面的数据到当前目录。
[root@localhost mysqladmin]# mysqldump -uroot -p321 westos > /mnt/westos.sql
#备份westos数据库,到/mnt下的westos.sql文件。
[root@localhost mysqladmin]# mysql -uroot -p321 -e "drop database westos;"
#删除westos数据库。
[root@localhost mysqladmin]# mysql -uroot -p321 -e "show databases;"
+--------------------+
| Database |
+--------------------+
| infor
mation_schema | #此时已删除
| hello |
| mysql |
| performance_schema |
+--------------------+
[root@localhost mysqladmin]# vim /mnt/westos.sql
CREATE DATABASE westos;
USE westos; #添加内容
DROP TABLE IF EXISTS `word`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
[root@localhost mysqladmin]# mysql -uroot -p321 < /mnt/westos.sql
#恢复westos数据库。
[root@localhost mysqladmin]# mysql -uroot -p321 -e "show databases;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| hello |
| mysql |
| performance_schema |
| westos | #恢复成功
[root@localhost mysqladmin]# mysql -uroot -p321 -e "drop database westos;"
#删除westos数据库
[root@localhost mysqladmin]# vim /mnt/westos.sql
/*CREATE DATABASE westos;
USE westos;
DROP TABLE IF EXISTS `word`; #注释掉
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
[root@localhost mysqladmin]# mysql -uroot -p321 -e " create database westos;" #创建一个数据库,注意数据库名必须于要恢复的库名一致
[root@localhost mysqladmin]# mysql -uroot -p321 < /mnt/westos.sql [root@localhost mysqladmin]# mysql -uroot -p321 -e "show databases;
"+--------------------+
| Database |
+--------------------+
| information_schema |
| hello |
| mysql |
| performance_schema |
| westos | #恢复成功
+--------------------+