1、首先在服务器上安装mysql:
sudo apt-get install mysql-server
2、如果遇到一个 报错信息,如下:
E: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/pool/main/m/mysql-5.7/mysql-server_5.7.30-0ubuntu0.18.04.1_all.deb 404 Not Found [IP: 100.100.2.148 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
则按提示,先进行 :apt-get update
然后继续执行第一步安装命令
3、安装完成后,会有提示
/etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
4、mysql安装完后,没有设置密码(如果出现让你输入密码,直接Enter下),你可以使用命令:
mysql -uroot -p
然后可以看到:
root@iZ2zefpqif8k98apxpff87Z:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.32-0ubuntu0.18.04.1 (Ubuntu)
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.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
5、就代表你成功登入了mysql数据库,接下来要做的是,添加一个有权限的,可以连接服务器的用户及设置密码;
6、登入后几个操作命令:
查看所有数据库:
show databases;
打开mysql库:
use mysql;
从mysql库查看 user表信息:
select user,host from user;
如:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
7、创建一个具体所有权限的用户debug5,密码为:debug5@no123
grant all privileges on *.* to debug5@"%" identified by "debug5@no123" with grant option;
8、显示 Query OK后,进行权限刷新
flush privileges;
9、然后退出数据库:
quit;
10、因为mysql默认是只支持本地访问,这步要把mysql对外权限开启
1)cd /etc/mysql/mysql.conf.d
2)sudo vim mysqld.cnf
然后把里面的
bind-address = 127.0.0.1
改为
bind-address = 0.0.0.0
11、最后重启下mysql服务
service mysql restart
12、此时你就可以在Windows使用Navicat进行远程连接服务器的mysql。
本博客源码Github地址:
请随手给个star,谢谢!