jdbc Óë mysqlÁ¬½Ó
JDBCÁ¬½ÓMySQL
JDBCÁ¬½ÓMySQL
¼ÓÔؼ°×¢²áJDBCÇý¶¯³ÌÐò
Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
JDBC URL ¶¨ÒåÇý¶¯³ÌÐòÓëÊý¾ÝÔ´Ö®¼äµÄÁ¬½Ó
±ê×¼Óï·¨£º
<protocol£¨Ö÷ҪͨѶÐÒ飩>:<subprotocol£¨´ÎҪͨѶÐÒ飬¼´Çý¶¯³ÌÐòÃû³Æ£©>:<data source identifier£¨Êý¾ÝÔ´£©>
MySQLµÄJDBC URL¸ñʽ£º
jdbc:mysql//[hostname][:port]/[dbname][?param1=value1][¶m2=value2]….
ʾÀý£ºjdbc:mysql://localhost:3306/sample_db?user=root&password=your_password
³£¼û²ÎÊý£º
user ̞
password ÃÜÂë
autoReconnect Áª»úʧ°Ü£¬ÊÇ·ñÖØÐÂÁª»ú£¨true/false£©
maxReconnect ³¢ÊÔÖØÐÂÁª»ú´ÎÊý
initialTimeout ³¢ÊÔÖØÐÂÁª»ú¼ä¸ô
maxRows ´«»Ø×î´óÐÐÊý
useUnicode ÊÇ·ñʹÓÃUnicode×ÖÌå±àÂ루true/false£©
characterEncoding ºÎÖÖ±àÂ루GB2312/UTF-8/…£©
relaxAutocommit ÊÇ·ñ×Ô¶¯Ìá½»£¨true/false£©
capitalizeTypeNames Êý¾Ý¶¨ÒåµÄÃû³ÆÒÔ´óд±íʾ
½¨Á¢Á¬½Ó¶ÔÏó
String url="jdbc:mysql://localhost:3306/sample_db?user=root&password=your_password";
Connection con = DriverManager.getConnection(url);
½¨Á¢SQL³ÂÊöʽ¶ÔÏó£¨Statement Object£©
Statement stmt = con.createStatem
Ïà¹ØÎĵµ£º
1£¬ÉèÖÃmysqlĬÈϱàÂë
Ê×ÏȲéѯһÏÂshow variables like 'character%';
È·¶¨ËùÓеÄcharacter¶¼ÉèÖóÉutf-8
²Î¿¼ http://www.diybl.com/course/7_databases/mysql/myxl/20081127/152726.html
mysql>show variables like 'character%';
+--------------------------+--------------------------- ......
mysql>use mysql;
mysql>update user set host='%' where user='root';
ÖØÆôMysql
sudo /etc/init.d/mysql restart
[sudo] password for wangzw:
*Stopping MySQL database server mysqld & ......
MYSQLÍü¼ÇROOTÃÜÂëºó£¿
ÐÞ¸ÄMySQLµÄµÇ¼ÉèÖãº
1.È¡ÏûȨÏÞ¹ÜÀí
±à¼ /mysql5.1/my.ini
ÔÚ[mysqld]µÄ¶ÎÖмÓÉÏÒ»¾ä£ºskip-grant-tables
ÀýÈ磺
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
Ä¿µÄÊÇΪÁË£º
Ìø¹ýMySQLµÄ·ÃÎ ......
mysql ´ó¶ÔÏó´æÈ¡:
¡¡¡¡ÀàÐÍÒ»°ãÓ¦¸ÃÓÃmediumblod,
¡¡¡¡blobÖ»ÄÜ´æ2µÄ16´Î·½¸öbyte,
¡¡¡¡mediumblodÊÇ24´Î·½,
¡¡¡¡Ò»°ãÀ´Ëµ¹»ÓÃÁË.longblobÊÇ32´Î·½ÓÐЩ´ó.
¡¡¡¡MYSQLĬÈÏÅäÖÃÖ»ÄÜ´æ1M´óСµÄÎļþ,ÒªÐÞ¸ÄÅäÖÃ,WIN°æ±¾µÄÔÚmysql.iniÎļþÖÐ
¡¡¡¡ÐÞ¸Ämax_allowed_packet,net_buffer_lengthµÈ¼¸¸ö²ÎÊý,»òÖ±½ÓSET GLOBAL va ......
MySQL³£ÓòÙ×÷»ù±¾²Ù×÷£¬ÒÔ϶¼ÊÇMySQL5.0ϲâÊÔͨ¹ýÊ×ÏÈ˵Ã÷Ï£¬¼ÇסÔÚÿ¸öÃüÁî½áÊøʱ¼ÓÉÏ£»£¨·ÖºÅ£©
1.µ¼³öÕû¸öÊý¾Ý¿â
mysqldump -u Óû§Ãû -p --default-character-set=latin1 Êý¾Ý¿âÃû > µ¼³öµÄÎļþÃû(Êý¾Ý¿âĬÈϱàÂëÊÇlatin1)
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2.µ¼³öÒ»¸ö±í
mysqldump -u Ó ......