Centos7 配置MySQL 和JDBC
程序员文章站
2022-07-12 13:53:12
...
一、准备
卸载已存在的MySQL
# rpm -qa | grep -i mysql
# rpm -e --nodeps PackageName
于MySQL官网根据需要下载,参考链接:
二、MySQL
配置
更新MySQL的yum源
# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum安装
# yum install mysql-community-server
测试
启动MySQL服务
# systemctl start mysqld.service
查看MySQL的初始密码
# grep 'password' /var/log/mysqld.log
登录
# mysql -uroot -p
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
使用简单密码则需要先执行以下两条
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
exit退出后即可使用新密码重新登录
附上:
关闭MySQL服务
# systemctl stop mysqld.service
MySQL的yum源移除
# yum remove mysql80-community-release-el7-3.noarch.rpm
三、JDBC
配置
将 mysql-connector-java-8.0.16-1.el7.noarch.rpm 解压,找到 mysql-connector-java.jar,将jar置于java的lib目录下/ext中。以本机为参考,目录是:/usr/lib/jvm/jre/lib/ext/
测试
写一个简单测试 test.java如下,编译运行查看结果即可。
import java.sql.*;
public class test {
public static void main(String[] args) {
try {
//Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost";
Connection con = DriverManager.getConnection(url,"root","password");
System.out.println("success...");
} catch(Exception e) {
System.out.println("failure!!!");
}
}
}
下一篇: mysql window免安装版配置流程