书目信息

中文名:《SQL必知必会(第4版)》

英文名:《Sams Teach Yourself SQL in 10 Minutes - Fourth Edition》

MySQL

MySQL - HomePage

Wiki - MySQL

在CentOS7系统中安装MySQL5.7

01-确认系统版本

# uname -a
Linux CentOS-7 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

02-下载MySQL的repo源

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

03-安装yum库

yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

04-安装MySQL

yum install -y mysql-community-server

05-启动MySQL服务

systemctl start mysqld

06-设置MySQL开机启动

systemctl enable mysqld

07-获取初始密码

[root@CentOS-7 ~]# cat /var/log/mysqld.log |grep password
2016-12-15T06:38:55.630758Z 1 [Note] A temporary password is generated for root@localhost: _=pPugkie3*t

08-使用初始密码登录

[root@CentOS-7 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

09-修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Bzbh2017!';
Query OK, 0 rows affected (0.04 sec)

10-设置远程登录

允许root用户使用密码从任何主机连接到mysql服务器

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Bzbh2017!' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> FLUSH PRIVILEGES;

11-查看数据库及表

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec) mysql>
mysql> use mysql;
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
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec) mysql>

12-关闭CentOS7防火墙

CentOS7默认启用firewall作为防火墙,可能会网络不通导致远程登录MySQL失败,这里是简单粗暴地关闭了防火墙。

查看防火墙状态:firewall-cmd --state

启动防火墙:systemctl start firewalld.service

停止防火墙:systemctl stop firewalld.service

禁止防火墙开机启动:systemctl disable firewalld.service

MySQL的主要配置文件

主配置文件: /etc/my.cnf

数据库文件存放位置: /var/lib/mysql/

数据库日志:/var/log/mysqld.log

MySQL数据库默认监听端口:

[root@CentOS-7 ~]# netstat -anp |grep 3306
tcp6 0 0 :::3306 :::* LISTEN 6976/mysqld

在CentOS7系统中安装MariaDB

MariaDB - HomePage

Wiki - MariaDB

MariaDB是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。

开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。

MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

01-确认系统版本

[root@CentOS-7 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

02-安装并启动MariaDB

[root@CentOS-7 ~]#yum -y install mariadb-server mariadb-devel
[root@CentOS-7 ~]#systemctl start mariadb.service
[root@CentOS-7 ~]#systemctl enable mariadb.service

03-mysql_secure_installation

[root@CentOS-7 ~]# 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
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
... 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
... 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. Remove test database and access to it? [Y/n] n
... skipping. 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@CentOS-7 ~]#

04-开始使用MariaDB

[root@CentOS-7 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec) MariaDB [(none)]>

建立练习环境

1-创建数据库

mysql> create database sqlbzbh;
Query OK, 1 row affected (0.00 sec) mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sqlbzbh |
| sys |
+--------------------+
5 rows in set (0.00 sec) mysql>

2-选择数据库

mysql> use sqlbzbh;
Database changed
mysql>
mysql> show tables;
Empty set (0.00 sec) mysql>

3-在选择的数据库中创建表和插入数据

获取脚本并执行:MySQL (and MariaDB) SQL scripts

示例:

mysql> CREATE TABLE Customers
-> (
-> cust_id char(10) NOT NULL ,
-> cust_name char(50) NOT NULL ,
-> cust_address char(50) NULL ,
-> cust_city char(50) NULL ,
-> cust_state char(5) NULL ,
-> cust_zip char(10) NULL ,
-> cust_country char(50) NULL ,
-> cust_contact char(50) NULL ,
-> cust_email char(255) NULL
-> );
Query OK, 0 rows affected (0.08 sec) mysql>
mysql> INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
-> VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@villagetoys.com');
Query OK, 1 row affected (0.00 sec) mysql>

4-验证表结构和数据

以MySQL为例,命令同样适用于MariaDB。

mysql> use sqlbzbh;
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
mysql>
mysql> show tables;
+-------------------+
| Tables_in_sqlbzbh |
+-------------------+
| Customers |
| OrderItems |
| Orders |
| Products |
| Vendors |
+-------------------+
5 rows in set (0.00 sec) mysql>
mysql> select * from Vendors;
+---------+-----------------+-----------------+------------+------------+----------+--------------+
| vend_id | vend_name | vend_address | vend_city | vend_state | vend_zip | vend_country |
+---------+-----------------+-----------------+------------+------------+----------+--------------+
| BRE02 | Bear Emporium | 500 Park Street | Anytown | OH | 44333 | USA |
| BRS01 | Bears R Us | 123 Main Street | Bear Town | MI | 44444 | USA |
| DLL01 | Doll House Inc. | 555 High Street | Dollsville | CA | 99999 | USA |
| FNG01 | Fun and Games | 42 Galaxy Road | London | NULL | N16 6PS | England |
| FRB01 | Furball Inc. | 1000 5th Avenue | New York | NY | 11111 | USA |
| JTS01 | Jouets et ours | 1 Rue Amusement | Paris | NULL | 45678 | France |
+---------+-----------------+-----------------+------------+------------+----------+--------------+
6 rows in set (0.00 sec) mysql>

参考信息

CentOS7中的systemctl命令

http://www.cnblogs.com/longrui/p/6071581.html

http://www.cnblogs.com/starof/p/4680083.html

读书笔记--SQL必知必会--建立练习环境的更多相关文章

  1. 读书笔记汇总 - SQL必知必会(第4版)

    本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...

  2. 读书笔记--SQL必知必会18--视图

    读书笔记--SQL必知必会18--视图 18.1 视图 视图是虚拟的表,只包含使用时动态检索数据的查询. 也就是说作为视图,它不包含任何列和数据,包含的是一个查询. 18.1.1 为什么使用视图 重用 ...

  3. 读书笔记--SQL必知必会12--联结表

    12.1 联结 联结(join),利用SQL的SELECT在数据查询的执行中联结表. 12.1.1 关系表 关系数据库中,关系表的设计是把信息分解成多个表,一类数据一个表,各表通过某些共同的值互相关联 ...

  4. SQL语法语句总结(《SQL必知必会》读书笔记)

    一.SQL语句语法 ALTER TABLE ALTER TABLE 用来更新已存在表的结构. ALTER TABLE tablename (ADD|DROP column datatype [NULL ...

  5. MySQL必知必会1-20章读书笔记

    MySQL备忘 目录 目录 使用MySQL 检索数据 排序检索数据 过滤数据 数据过滤 用通配符进行过滤 用正则表达式进行搜索 创建计算字段 使用数据处理函数 数值处理函数 汇总数据 分组数据 使用子 ...

  6. 《mysql必知必会》读书笔记--存储过程的使用

    以前对mysql的认识与应用只是停留在增删改查的阶段,最近正好在学习mysql相关内容,看了一本书叫做<MySQL必知必会>,看了之后对MySQL的高级用法有了一定的了解.以下内容只当读书 ...

  7. 【SQL必知必会笔记(3)】SELECT语句的WHERE子句数据过滤操作

    上个笔记主要介绍了利用SELECT语句检索单个/多个/所有列,并利用DISTINCT关键字检索具有唯一性的值.利用LIMIT/OFFSET子句限制结果:以及利用ORDER BY子句排序检索出的数据,主 ...

  8. 0005 《SQL必知必会》笔记01-SELECT语句

    1.SELECT基本语句: SELECT 字段名1,···,字段名n FROM 表名 2.检索所有字段,用"*"替换字段名,这会导致效率低下 SELECT * FROM 表名; 3 ...

  9. 《SQL必知必会》学习笔记二)

    <SQL必知必会>学习笔记(二) 咱们接着上一篇的内容继续.这一篇主要回顾子查询,联合查询,复制表这三类内容. 上一部分基本上都是简单的Select查询,即从单个数据库表中检索数据的单条语 ...

随机推荐

  1. redux学习

    redux学习: 1.应用只有一个store,用于保存整个应用的所有的状态数据信息,即state,一个state对应一个页面的所需信息 注意:他只负责保存state,接收action, 从store. ...

  2. java中易错点(一)

    由于replaceAll方法的第一个参数是一个正则表达式,而"."在正则表达式中表示任何字符,所以会把前面字符串的所有字符都替换成"/".如果想替换的只是&qu ...

  3. 反应器(Reactor)和主动器(Proactor)

    网络方面用的比较多的库是libevent和boost.asio,两者都是跨平台的.其中libevent是基于Reactor实现的,而boost.asio是基于Proactor实现的.Reactor和P ...

  4. java观察者模式

      像activeMQ等消息队列中,我们经常会使用发布订阅模式,但是你有没有想过,客户端时如何及时得到订阅的主题的信息?其实就里就用到了观察者模式.在软件系统中,当一个对象的行为依赖于另一个对象的状态 ...

  5. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  6. 设计模式之工厂模式VS抽象工厂

    一.工厂模式主要是为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的. 工厂模式在<Java与模式>中分为三类:1)简单工厂模式(Simple Factor ...

  7. git &github 快速入门

    本节内容 github介绍 安装 仓库创建& 提交代码 代码回滚 工作区和暂存区 撤销修改 删除操作 远程仓库 分支管理 多人协作 github使用 忽略特殊文件.gitignore 1.gi ...

  8. IP报头

      位字段的值设置为二进制的0100表示IP版本4(IPv4).设置为0110表示IP版本6(IPv6)   位,它表示32位字长的IP报头长度,设计报头长度的原因是数据包可选字段大小会发生变化.IP ...

  9. angular中使用ngResource模块构建RESTful架构

    ngResource模块是angular专门为RESTful架构而设计的一个模块,它提供了'$resource'模块,$resource模块是基于$http的一个封装.下面来看看它的详细用法 1.引入 ...

  10. 【腾讯优测干货分享】如何降低App的待机内存(二)——规范测试流程及常见问题

    本文来自于腾讯优测公众号(wxutest),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/806TiugiSJvFI7fH6eVA5w 作者:腾讯TMQ专项测 ...