(一)Mysql第一次登陆
1. 设置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
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)