美文网首页
mysql连接

mysql连接

作者: 糖糖_6050 | 来源:发表于2019-04-02 09:59 被阅读0次

命令行连接

linux和windows下连接数据库的命令是一样的,需要在安装了mysql客户端的机器上执行命令,可远程连接,但需做了相应配置

本地连接

linux环境
root@iZwz9e3q231prkv5pagk38Z:~# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 405655
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| file_server        |
| gvsuncms           |
| gvsuntms           |
| gvsuntms_new       |
| mysql              |
| performance_schema |
| sys                |
| test               |
| ycitlimstms        |
+--------------------+
10 rows in set (0.00 sec)

windows环境下

D:\Program Files (x86)\mysql-5.7.24-winx64\bin>mysql -uroot -p
Enter password: *******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| 教学本地           |
| auditserver        |
| datashare          |
| directory_server   |
| file_server        |
| gvsuntms_new       |
| instrumentsyc      |
| iot                |
| limsproduct        |
| mysql              |
| performance_schema |
| security           |
| sutcmslims2        |
| sys                |
| test               |
| ycitlimstms        |
+--------------------+
17 rows in set (0.01 sec)

远程连接

远程连接和本地连接需要的环境是一致的,但是目标数据库需要允许当前用户从当前地址连接

D:\Program Files (x86)\mysql-5.7.24-winx64\bin>mysql -uroot -p -h ********(远程数据库ip) -P3306
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3323492
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>show grants for root;
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.04 sec)

可以看到对于root这个用户,服务器允许的是所有地址可登陆,如果服务器修改了端口号,-P后加的端口号应该改为设置的端口号,如果使用的默认,则可以不指定端口号

工具连接

navicat连接

安装navicat客户端之后,点击文件---新建连接---mysql


image.png

输入数据库相关信息,注意连接名最好写清楚哪个项目用来做什么的数据库,不要直接用ip,防止后期分不清楚。


image.png
填写完毕之后点击连接测试,显示连接成功则点击确定保存,如果报错,则检查信息是否有错误
image.png
image.png

相关文章

网友评论

      本文标题:mysql连接

      本文链接:https://www.haomeiwen.com/subject/ipqgvqtx.html