[root@mail ~]# yum install mariadb mariadb-server -y
[root@mail mysql]# systemctl restart mariadb
[root@mail mysql]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
[root@mail ~]# mysql
mysql mysqldump mysql_setpermission
mysqlaccess mysqldumpslow mysqlshow
mysqladmin mysql_find_rows mysqlslap
mysqlbinlog mysql_fix_extensions mysqltest
mysqlbug mysqlhotcopy mysql_tzinfo_to_sql
mysqlcheck mysqlimport mysql_upgrade
mysql_convert_table_format mysql_install_db mysql_waitpid
mysqld_multi mysql_plugin mysql_zap
mysqld_safe mysql_secure_installation
[root@mail mysql]# mysql_secure_installation
/usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令
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!
Bydefault, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without havingto have a user account created for
them. This is intended onlyfor testing, andto make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y(删除匿名用户)
Normally, root should only be allowed toconnectfrom'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]Y(禁止root管理员从远程登录)
Bydefault, MariaDB comes with a database named 'test' that anyone can
access. This is also intended onlyfor testing, and should be removed
before moving into a production environment.
Remove test databaseand access to it? [Y/n] Y(删除test数据库并取消对它的访问权限)
- Dropping test database...
... Success!
- Removing privilegeson 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] Y(刷新授权表,让初始化后的设定立即生效)
... 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@mail mysql]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands endwith ; or \g.
Your MariaDB connection id is 10
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 inset (0.02 sec)
//重置root管理员密码
MariaDB [(none)]> SET password = PASSWORD('redhat');
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
管理账户以及授权
命令
作用
GRANT 权限 ON 数据库.表单名称 TO 账户名@主机名
对某个特定数据库中的特定表单给予授权
GRANT 权限 ON 数据库.* TO 账户名@主机名
对某个特定数据库中的所有表单给予授权
GRANT 权限 ON . TO 账户名@主机名
对所有数据库及所有表单给予授权
GRANT 权限1,权限2 ON 数据库.* TO 账户名@主机名
对某个数据库中的所有表单给予多个授权
GRANT ALL PRIVILEGES ON . TO 账户名@主机名
对所有数据库及所有表单给予全部授权
MariaDB [(none)]> create user hcie@localhost identified by 'hcie';
QueryOK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant select,update,delete,insert on mysql.* to hcie;
QueryOK, 0 rows affected (0.03 sec)
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase 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 [(none)]> show grants for hcie@localhost;
+-------------------------------------------------------------------------------------------------------------+
| Grants for hcie@localhost |
+-------------------------------------------------------------------------------------------------------------+
| GRANTUSAGEON *.* TO'hcie'@'localhost'IDENTIFIEDBYPASSWORD'*D6CDD5D8461B882D121CAC3EE6A028367E198649' |
+-------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> show grants for hcie;
+-----------------------------------------------------------------+
| Grants for hcie@% |
+-----------------------------------------------------------------+
| GRANTUSAGEON *.* TO'hcie'@'%' |
| GRANTSELECT, INSERT, UPDATE, DELETEON `mysql`.* TO'hcie'@'%' |
+-----------------------------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> revoke select,update,delete,insert on mysql.* from hcie;
QueryOK, 0 rows affected (0.00 sec)