安装
sudo apt update
sudo apt install mysql-server
然后就会提示你为mysql设置root用户密码了
---------------------------------------------------------------------------------
查看服务状态
sudo service mysql status
默认打开自启动
禁用自启动时现在 disabled
停止/开启/重启
sudo service mysql stop/start/restart
开启/关闭开机自启
systemctl enable/disable mysqld
查看是否自启状态
systemctl list-unit-files | grep mysqld
试登录一下
mysql -uroot -p
可以下载MySQL的图形界面客户端
https://dev.mysql.com/downloads/workbench/
修改端口
vi /etc/mysql/mysql.conf.d/mysqld.cnf
# For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log
在末行添加 port = 3310
然后重启服务
service mysql restart
登录
mysql -u root -p
查表,看端口是否修改完成
mysql> show global variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3310 | +---------------+-------+ 1 row in set (0.01 sec) mysql> use mysql;
修改权限表策略,让root用户的host不受限
mysql> use mysql;
mysql> update user set host='192.168.%' where user = 'root'; 或 mysql> update user set host='%' where user = 'root';
刷新权限缓存
mysql> flush privileges;
我的mysql装在了虚拟机Ubuntu上,并配置了NAT和桥接两个虚拟网卡
然后在 Windows 用 MySQL Workbench 连接 虚拟机上的 MySQL
JDBC 连接 mysql8
驱动 com.mysql.cj.jdbc.Driver 下载地址:https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.22.zip
jdbc:mysql://yourhost:3310/database?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
指定不使用SSL,时区设东8区
至于使用SSL的方法见:https://dev.mysql.com/doc/refman/8.0/en/creating-ssl-files-using-openssl.html
依赖Maven/Gradle
https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.22