[MySQL安装] 安装后测试MySQL是否能正常使用

在MySQL安装目录下的bin目录,有很多”mysql programs程序/小工具“,它们是存在于"操作系统linux/windows"层面,而不是”数据库“层面的,就好比一个探测器,不需要挖地到地下面,就可以探索到地下面有什么东西了,很适合自动化运维操作,在操作系统上去登录数据库,而不是直接进入到数据库中

 

文章目录

在”操作系统“层面,对服务器的操作有三种

1.查看服务器的状态(open or close)

2.打开

3.关闭

 

在操作系统层面

1.实现”show databases“ 查看数据库

2.实现”show tables“ 查看某个数据库里面的表

3.实现”select * from table“查看表的内容

 

 

1.检查服务器状态

我想知道现在mysql服务器是关闭着的,还是打开着的

关闭着的

[root@localhost mysql]# ./bin/mysqladmin version
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

打开着/连接着的

[root@localhost mysql]# ./bin/mysqladmin version
./bin/mysqladmin  Ver 8.42 Distrib 5.5.47, for linux2.6 on x86_64
Copyright (c) 2000, 2015, 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.

Server version          5.5.47
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 17 hours 55 min 2 sec

Threads: 1  Questions: 48  Slow queries: 0  Opens: 54  Flush tables: 2  Open tables: 0  Queries per second avg: 0.000

这个操作底层肯定会调用”进程“查询

ps -ef | grep mysql
netstat -ntlp | grep 3306

 

2.打开

启动mysql服务器的本质,是启动”mysqld进程“ 

”启动一万年“,所以记得在命令末尾加上&

1./usr/local/mysql/bin/mysqld --user=mysql &

2./usr/local/mysql/bin/mysqld_safe --user=mysql &

 

3.关闭

在每次关闭linux操作系统之前,一定得关闭MySQL服务器

/usr/local/mysql/bin/mysqladmin shutdown
151228 09:57:55 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
[1]+  Done                    ./mysqld_safe --user=mysql

  

1.在操作系统层面实现”show databases“ 查看数据库

所有在”操作系统“层面能够操作”数据库“层面的操作,都需要通过中介媒介去达成,而这个”中介“就是”mysql/bin里面的程序“

[root@localhost ~]# /usr/local/mysql/bin/mysqlshow
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

 

2.实现”show tables“ 查看某个数据库里面的表

[root@localhost ~]# /usr/local/mysql/bin/mysqlshow test
Database: test
+------------+
|   Tables   |
+------------+
| advisor    |
| classroom  |
| course     |
| department |
| instructor |
| prereq     |
| score      |
| section    |
| set1       |
| set2       |
| student    |
| t1         |
| t2         |
| takes      |
| teaches    |
| the_number |
| time_slot  |
+------------+

  

3.实现”select * from table“查看表的内容

我们在数据库里执行sql语句,需要使用 mysql 客户端先链接,所以在操作系统里执行sql语句也得通过"mysql客户端"这个"黑中介"

[root@localhost ~]# /usr/local/mysql/bin/mysql -e "select host,user,password from mysql.user" 
+-----------------------+------+----------+
| host                  | user | password |
+-----------------------+------+----------+
| localhost             | root |          |
| localhost.localdomain | root |          |
| 127.0.0.1             | root |          |
| ::1                   | root |          |
| localhost             |      |          |
| localhost.localdomain |      |          |
+-----------------------+------+----------+

其中e这个option是指”execute执行命令“的意思

 -e, --execute=name  Execute command and quit. (Disables --force and history file.)

 

详细阅读: Testing the Server

 

总结:以前很早听说学习ORACLE最好的方式document,因为由浅入深,其实MYSQL也是一样,大部分的书(除非介绍原理)都不可能做到比document更详细,问题仅仅在于你是否能突破对于”英文阅读“的障碍而已,能看英文,还意味着能到 statck exchange各种论坛上去交流,比国内的平台回复速度要更快更准确

转载于:https://www.cnblogs.com/hellotracy/articles/5081581.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值