连接到 MySQL 服务器由三种办法,使用 mysql 命名 、使用 Navicat MySQL 客户端和使用各种开发语言连接
使用 mysql 命令连接
mysql 命令一般会随着 MySQL 安装而自带,这是最基本的也是最容易连接到 MySQL 服务器的方式
可以使用下面的命令连接到 MySQL 服务器
mysql -u [用户名] -p [密码,可以不输入]
例如使用 root 用户登录
[root@locahost ~]# mysql -u root -p
连接成功后会显示 mysql> 命令提示窗口,然后我们就可以开始使用这个连接运行任何 SQL 语句
命令演示如下
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
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)]>
我们使用了 root 用户登录到 MySQL 服务器,我们也可以使用其他 MySQL 用户登录
如果用户权限足够,任何用户都可以在 MySQL 的命令提示窗口中进行