centos7 mysql安装和连接
1 安装
mysql 安装 有多种方式,常用两种:
1.使用 yum 仓库 安装 https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
2.使用rpm包安装 https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
https://dev.mysql.com/doc/refman/5.7/en/installing.html
https://blog.csdn.net/lovefengruoqing/article/details/83687557
https://www.jianshu.com/p/13e251f821c7
https://www.cnblogs.com/raicho/p/12511998.html
2 连接
## 查看 mysql 命令 的使用帮助
mysql --help
## -h 和 -P可以省略,默认是本机localhost,3306端口
##注意 端口 -P 大写, 密码 -p 小写
## 参数名后面的空格可以省略
mysql -h host -P port -u user -p
Enter password: ********
## 如果要显式指定 密码 -p 后面不能有空格
mysql -uuser -ppassword
## 指定 数据库,这样连接后就直接到这个库
##第一个不带短横杠(-)的参数就是数据库名
$> mysql -h host -u user -p databaseName
Enter password: ********
## 退出
mysql> QUIT
Bye
如果在登录时 出现错误 “ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)” ,可能是 mysql服务器的守护进程没有启动
详见:https://www.cnblogs.com/Lam7/p/6090975.html
https://dev.mysql.com/doc/refman/5.7/en/command-line-options.html
3 提示
登录mysql 后:语句 以 分号结尾, 可以多行。
/*
多行注释
*/
/*ctrl + c 或 \c 可以取消当前语句 */
mysql> SELECT
-> USER()
-> \c
mysql>
| 提示 | 意思 |
|---|---|
| mysql> | 准备新查询 |
| -> | 正在等待多行查询的下一行 |
| '> | 等待下一行,等待以单引号开始的字符串完成(') |
| "> | 等待下一行,等待以双引号开始的字符串完成 (") |
| `> | 等待下一行,等待以反勾号开始的标识符完成 (`) |
| /*> | 等待下一行,等待注释完成 /* |

浙公网安备 33010602011771号