今天开始通过自学MySQL总结一些方法和一些基础的内容,写在这里,和大家一起讨论学习进步。(一定会坚持写到最后)
安装部署直接跳过,我使用的版本是5.7.33,直接开写
目录
MySQL学习总结之路(第一章:服务与数据库管理)
1、启动和关闭服务指令
1.1windows下Mysql5.7官方MSI安装地址(选择自己心仪的版本安装):
https://downloads.mysql.com/archives/installer/
1.1.1:win7 会遇到的问题:遇到无法定位程序输入点fesetround于动态链接库 解决办法:
下载C++库地址:
https://support.microsoft.com/en-us/help/3138367/update-for-visual-c-2013-and-visual-c-redistributable-package
下载选中的安装完成,继续下一步即可
1.2、windows下(mysql57为mysql服务名称):
启动:net start mysql57
关闭:net stop mysql57
1.3、linux下(mysql 为mysql服务名称):
启动:[root@localhost ~]service mysql start
关闭:[root@localhost ~]service mysql stop
1.4、windows下cmd窗体进入mysql:
cd到mysql安装的bin目录下:
C:Windowssystem32>cd C:Program FilesMySQLMySQL Server 5.7in
连接mysql服务器:
C:Program FilesMySQLMySQL Server 5.7in>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.17-log MySQL Community Server (GPL)
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.
mysql>
mysql 代表客户端命令,-u 后面跟连接的数据库用户,-p 表示需要输入密码。
1.4、数据库管理
1.4.1、创建一个orderManage数据库
mysql> create database orderManage;
Query OK, 1 row affected (0.00 sec)
1.4.2、展示所有的数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cluster |
| mysql |
| test |
| orderManage|
+--------------------+ 5 rows in set (0.00 sec)
可以发现,在上面的列表中除了刚刚创建的orderManage外,还有另外 4 个数据库,它们都是安装
MySQL 时系统自动创建的,其各自功能如下。
1、 information_schema:主要存储了系统中的一些数据库对象信息。比如用户表信息、列信息、权限信息、字符集信息、分区信息等。
2、 cluster:存储了系统的集群信息。
3 、mysql:存储了系统的用户权限信息。
4、 test:系统自动创建的测试数据库,任何用户都可以使用。
1.4.3、选择进入某一个数据
选择进入orderManage数据库中:
mysql> use ordermanage;
Database changed
由此可以发现,选择进入数据库时候,数据库的名称是不区分大小写的
1.4.4、查看此数据库中的所有表
mysql> show tables;
Empty set (0.00 sec)
此时,显示orderManage数据库中是没有表的(Empty set表示操作结果为空)
1.4.5、删除数据库
mysql> drop database ordermanage;
Query OK, 0 rows affected (0.01 sec)
1.5、配置MySQL允许远程访问
通过ip连接出现如下问题:
解决方法:
以root 用户进入mysql数据库,并查询登录用户信息:
mysql -u root -p use mysql; select host from user where user = 'root'
将host设置为%
update user set host='%' where user='root';
Host修改完成后记得执行flush privileges使配置立即生效即可
flush privileges;