软件:
cmake-2.8.12.1.tar.gz
mysql-5.5.31.tar.gz
1、安装cmake
(如果存在旧的,卸载掉,卸载命令apt-get autoremove cmake)
root@ubuntu:/usr/local# tar -zvxf cmake-2.8.12.1.tar.gz root@ubuntu:/usr/local# cd cmake-2.8.12.1 root@ubuntu:/usr/local/cmake-2.8.12.1# ./configure root@ubuntu:/usr/local/cmake-2.8.12.1# make root@ubuntu:/usr/local/cmake-2.8.12.1# make install
2、创建mysql的安装目录及数据库存放目录
root@ubuntu:/usr/local# mkdir -p /usr/local/mysql //安装mysql root@ubuntu:/usr/local# mkdir -p /usr/local/mysql/data //存放数据库
3、创建mysql用户及用户组并赋予数据存放目录权限
root@ubuntu:/usr/local# groupadd mysql root@ubuntu:/usr/local# useradd -r -g mysql mysql root@ubuntu:/usr/local# chown mysql.mysql -R /usr/local/mysql/data/
4、安装mysql
root@ubuntu:/usr/local# tar -zvxf mysql-5.5.31.tar.gz root@ubuntu:/usr/local# cd mysql-5.5.31 root@ubuntu:/usr/local/mysql-5.5.31# cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DENABLED_LOCAL_INFILE=1 \ root@ubuntu:/usr/local/mysql-5.5.31# make root@ubuntu:/usr/local/mysql-5.5.31# make install
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
5、配置:
root@ubuntu:/usr/local/mysql# cp support-files/my-medium.cnf /etc/my.cnf root@ubuntu:/usr/local/mysql# cp support-files/mysql.server /etc/init.d/mysqld //将mysql的启动服务添加到系统服务中 root@ubuntu:/usr/local/mysql# chmod 755 /etc/init.d/mysqld //设置软连接, root@ubuntu:/usr/local# ln -s /usr/local/mysql/bin/mysql /usr/bin
6、启动
root@ubuntu:/usr/local/mysql# cd /usr/local/mysql root@ubuntu:/usr/local/mysql# scripts/mysql_install_db --user=mysql root@ubuntu:/usr/local/mysql# /etc/init.d/mysqld start //启动数据库 root@ubuntu:/usr/local/mysql# mysql -u root -p //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。 修改root密码 mysql>use mysql ; mysql>update user set password=PASSWORD("aaa") where user='root'; mysql>FLUSH PRIVILEGES;
7、测试
mysql> create database mytest; Query OK, 1 row affected (0.00 sec) mysql> use mytest; Database changed mysql> create table student(id int auto_increment,name varchar(100),age int,address varchar(255),tel int,score float,primary key(id)); Query OK, 0 rows affected (0.01 sec) mysql> insert into student values(NULL,'zhangsan',22,'china',13126668725,99); Query OK, 1 row affected, 1 warning (0.02 sec) mysql> insert into student values(NULL,'lisi',23,'china hebei',13126668725,96); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from student; +----+----------+------+-------------+------------+-------+ | id | name | age | address | tel | score | +----+----------+------+-------------+------------+-------+ | 1 | zhangsan | 22 | china | 2147483647 | 99 | | 2 | lisi | 23 | china hebei | 2147483647 | 96 | +----+----------+------+-------------+------------+-------+ 2 rows in set (0.05 sec)
参考:
http://www.cnblogs.com/fly1988happy/archive/2011/11/21/2257682.html(安装参考)
http://dev.mysql.com/doc/refman/5.1/zh/preface.html(Mysql中文手册和教程)
http://downloads.mysql.com/archives/get/file/mysql-5.5.31.tar.gz (mysql下载地址)
http://www.cmake.org/cmake/resources/software.html(cmake下载地址)