(一)Mysql第一次登陆

1. 设置root密码

参考mysql如何修改root用户的密码

mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
 
mysql -u root -p
123456

2. 远程连接问题

Host '10.66.91.2' is not allowed to connect to this MySQL serverConnection closed by foreign host.
解决方法:

grant all PRIVILEGES on ld.* to root@'10.66.91.2'  identified by '123456';

3. java连接mysql

参考让Java和MySQL连接起来

package main;

import java.sql.*;

public class Test {

    public static void main(String[] args) throws ClassNotFoundException,SQLException{
        // TODO Auto-generated method stub
        Class cs = Class.forName("com.mysql.jdbc.Driver");
        System.out.println(cs.getName());
        
        Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/ld","root","123456");
        Statement state=conn.createStatement();
        // ResultSet result = state.executeQuery("select * from pet where name='dd'");
        ResultSet result = state.executeQuery("select * from pet");
        while(result.next()){
            String strName = result.getString(1);
            String strOwner = result.getString(2);
            Date dateBirthday = result.getDate(3);
            Timestamp timestampDeath = result.getTimestamp(4);
            Timestamp timestampWedding = result.getTimestamp(5);
            System.out.printf("%s %s %s %s %s\n",strName, strOwner, dateBirthday, timestampDeath, timestampWedding);
        }
        
        conn.close();
    }

}

4. 备份和恢复

C:\Users\liudong11>mysqldump -u root -p --databases ld > dump.sql
Enter password: **********
mysql> source dump.sql

5. 查看mysql端口

mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)

转载于:https://www.cnblogs.com/walkinginthesun/p/10094769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值