1. Download MySQL 5.5 at
http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-5.5.17-1.linux2.6.x86_64.tar/from/ftp://ftp.iij.ad.jp/pub/db/mysql/
2. 解压:
tar -xf MySQL-5.5.17-1.linux2.6.x86_64.tar
3. 安装MySQL Server:
rpm -ivh MySQL-server-5.5.17-1.linux2.6.x86_64.rpm
in CentOS6, you will get issues with old mysql-libs confict, run the command to remove the old one:
==============================
[root@localhost MySQL]# yum erase mysql-libs
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.47-4.el6 set to be erased
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-2.1.el6_0.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: redland-1.0.7-11.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-2.1.el6_0.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: redland-1.0.7-11.el6.x86_64
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-2.1.el6_0.x86_64
--> Running transaction check
......
==============================
4. 安装MySQL Client:
rpm -ivh MySQL-client-5.5.17-1.linux2.6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
=======================================
a. 数据库目录
/var/lib/mysql/
b. 配置文件
/usr/share/mysql(mysql.server命令及配置文件)
c. 相关命令
/usr/bin(mysqladmin mysqldump等命令)
d. 启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)
17. create user that can connect with any host:
a. mysql -uroot -p
b. create user 'yonghui'@'%' identified by 'yonghuipwd';
18. grant privileges to new user:
mysql -uroot -p
mysql> grant all privileges on *.* to 'yonghui'@'%' with grant option;
19. create connection:
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);