fodora lianjie mysql_Fedora中允许mysql远程访问的几种方式

Fedora中允许mysql远程访问,可以使用以下两种方式:

a、改表。

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

b、授权。

例如,你想root使用123456从任何主机连接到mysql服务器。

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码

mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;

mysql>FLUSH RIVILEGES

import java.sql.; public class lianjie { // JDBC连接MySQL的URL、用户名和密码 static final String JDBC_URL = "jdbc:mysql://localhost:3306/sys?serverTimezone=GMT%2B8&useSSL=false"; static final String USERNAME = "root"; static final String PASSWORD = "zoushenyu"; public static void main(String[] args) throws SQLException { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // 连接MySQL数据库 conn = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD); // 插入数据 stmt = conn.createStatement(); String sql = "INSERT INTO guoguan (id, name, age, birthday, salary) VALUES (105, '张三', 20, '2000-01-01', 4300)"; stmt.executeUpdate(sql); // 修改数据 sql = "UPDATE guoguan SET salary = 4500 WHERE id = 105"; stmt.executeUpdate(sql); // 删除数据 / sql = "DELETE FROM guoguan WHERE id = 105"; stmt.executeUpdate(sql);*/ // 查询数据 sql = "SELECT * FROM guoguan"; rs = stmt.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); int age = rs.getInt("age"); Date birthday = rs.getDate("birthday"); double salary = rs.getDouble("salary"); System.out.printf("%d %s %d %s %.2f\n", id, name, age, birthday.toString(), salary); } } catch (SQLException e) { e.printStackTrace(); } finally { // 释放资源 if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } } } use sys; create table guoguan( id int, name varchar(40), age int, birthday date, salary double ); select * from guoguan; 请为这两份代码写一段说明文档,要尽量详细
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值