总览
网上都说的清楚了,主要分为服务是否启动、3306端口是否放开、远程访问权限是否开启。
- 服务正常启动不用说。
3306端口
要么在防火墙里面放开允许访问,如果不想去加放开3306端口配置就直接把防火墙关闭。- 远程访问权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
1、Linux开启mysql
启动mysql服务 :
service mysqld start
或者设置开机自启 :
chkconfig mysqld on
2、Navicat连接Linux下MySQL
1.进入数据库
-h 主机
一般省略
-u 用户
跟随的是你的账户密码
-p 密码
可以省略,敲击回车后输入
mysql -u root -p
需要输入root密码,如果有宝塔面板的话,可以在此处查看
注意: 数据库指令以;
结束,不要自作聪明把分号去掉
2.给其他电脑赋予权限
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
123456
是MySQL密码
此时:
mysql> SELECT user,host FROM mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
FLUSH PRIVILEGES;
exit;
4.查看防火墙状态
systemctl status firewalld.service
5.若防火墙开启则关闭防火墙
systemctl stop firewalld.service
在查看防火墙的状态:disavtive(dead),表示关闭了(重启之后还会打开)
3、放开3306端口
4、Windows Navicat 设置
4.1 如果第三步放开了3306端口情况下
此时用户即root,密码就是GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
中设置的密码
4.2 如果第三步未放开3306端口情况下要通过SSH链接
用户名为root,密码是宝塔面板中的root密码,此时可不是上述4.1中设置的那个密码
SSH 用户名root,密码是22端口链接的linux登录密码
4、mysql 指令学习
mysql -u root -p 登录
[root@VM-12-9-centos ~]# mysql -u mtodo -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 63
Server version: 5.6.50-log Source distribution
Copyright (c) 2000, 2020, 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.
show database;查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mtodo |
+--------------------+
2 rows in set (0.00 sec)
如果忘记敲击分号;
,在下一行继续敲回车就可以了
use mysql; 选择数据库
mysql> use mtodo
Database changed
数据库的创建删除
create database `数据库名称` [数据库选项];
选项:选定字符集 charset = utf8
数据库的删除
drop database `数据库名称`;
5、视频学习
推荐: MySQL入门