01.mysql概念+安装+安全配置
MySQL服务概述
MySQL服务概述:
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。
MySQL是最流行的关系型数据库管理系统,在WEB应用方面MySQL是最好的RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。
MySQL是一种关联数据库管理系统,关联数据库将数据保存在丌同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
MySQL所使用的SQL语言是用于访问数据库最常用标准化语言。MySQL软件采用了双授权政策,它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。由于其社区版的性能卓越,搭配PHP和Apache可组成良好的开发环境。
双授权政策:开放源代码版本和商业版本。
例如:很多公司出售应用软件,例如Microsoft、Apple和Oracle;
如Red Hat和IBM,则通过为其开放源代码软件提供销售支援、托管戒咨询等服务来进行赚钱。但鲜为人知的是,企业可以透过开放源代码发布仕们的软件,也可以同时销售该软件的商业版本。
MySQL安装
centos7-yum安装
[root@localhost ~]# yum -y install mariadb-server mariadb
mariadb-server:为服务端
mariadb:为客户端
centos6-yum安装
[root@localhost ~]# yum -y install mysql-server mysql
查看mysql版本
[root@localhost ~]# mysql -V
mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1
启动用mysql
启用mysql
[root@localhost ~]# systemctl start mariadb.service
设置开机自启动
[root@localhost ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
查看mysql状态
[root@localhost ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-12-16 16:08:34 CST; 27s ago
Main PID: 89193 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─89193 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─89354 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: MySQL ma...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: Please r...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: The late...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: You can ...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: http://d...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: Consider...
Dec 16 16:08:31 localhost.localdomain mariadb-prepare-db-dir[89113]: https://...
Dec 16 16:08:32 localhost.localdomain mysqld_safe[89193]: 201216 16:08:32 mys...
Dec 16 16:08:32 localhost.localdomain mysqld_safe[89193]: 201216 16:08:32 mys...
Dec 16 16:08:34 localhost.localdomain systemd[1]: Started MariaDB database se...
Hint: Some lines were ellipsized, use -l to show in full.
查看mysql端口
[root@131-server ~]# netstat -anutp | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 22240/mysqld
tcp6 0 0 :::33060 :::* LISTEN 22240/mysqld
mysql登录
cat /var/log/mysqld.log | grep password
mysql第一次安装时有默认密码,查看mysql默认密码
[root@131-server ~]# cat /var/log/mysqld.log | grep password
2020-12-26T07:46:51.321600Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xeNSxgyIF5_n
mysql
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
mysql –h IP –uUser –pPASSWORD –PPORT
[root@localhost ~]# mysql -uroot -p123456 -h127.0.0.1 -P3306
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
mysql安全配置
安全配置
[root@localhost ~]# mysql_secure_installation
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密码,y表示设置,n表示不设置
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] y #是否允许匿名用户登录,生产环境建议不允许。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] n #是否禁止root用户远程登录,根据需求设置。y表示允许,n表示不允许
... skipping.
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.
是否删除test数据库
Remove test database and access to it? [Y/n] y #是否删除test数据库,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] #是否重新加载权限表,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 ~]# mysql -uroot -p123456 -h127.0.0.1 -P3306
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation 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)

浙公网安备 33010602011771号