您的位置:首页 > 数据库 > MySQL

linux 源代码安装mysql(借鉴加修改)

2014-02-11 20:24 218 查看
1.假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源文件(1)先安装cmake(mysql5.5以后是通过cmake来编译的)
[root@ rhel5 local]#tar -zxv -f cmake-2.8.4.tar.gz
[root@ rhel5 local]#cd cmake-2.8.4
[root@ rhel5 cmake-2.8.4]#./configure
[root@ rhel5 cmake-2.8.4]#make
[root@ rhel5 cmake-2.8.4]#make install

(2)创建mysql的安装目录及数据库存放目录
[root@ rhel5~]#mkdir -p /usr/local/mysql                 //安装mysql
[root@ rhel5~]#mkdir -p /usr/local/mysql/data            //存放数据库
(3)创建mysql用户及用户组
[root@ rhel5~]groupadd mysql
[root@ rhel5~]useradd -r -g mysql mysql
(4)安装mysql
[root@ rhel5 local]#tar -zxv -f mysql-5.5.10.tar.gz -C /usr/local/src
[root@ rhel5 local]#cd /usr/local/src mysql-5.5.10
[root@ rhel5 mysql-5.5.10]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ --指定安装路径
-DWITH_INNOBASE_STORAGE_ENGINE=1 \--启用innodb存储引擎
-DENABLED_LOCAL_INFILE=1 \--允许通过本地导入数据
-DDEFAULT_CHARSET=utf8 \--指定默认的语言编码
-DEXTRA_CHARSETS=all \--扩展语言编码
-DDEFAULT_COLLATION=utf8_general_ci \--排序语言编码
-DSYSCONFDIR=/etc \--配置文件的目录
-DMYSQL_DATADIR=/usr/local/mysql/data \--数据目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \--socket目录
[root@ rhel5 mysql-5.5.10]#make
[root@ rhel5 mysql-5.5.10]#make install



注意事项:重新编译时,需要清除旧的对象文件和缓存信息。# make clean# rm -f CMakeCache.txt# rm -rf /etc/my.cnf2.配置(1)设置目录权限
[root@ rhel5~]# cd /usr/local/mysql
[root@ rhel5 mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql
[root@ rhel5 mysql]# chown -R mysql:mysql data
(2)
[root@ rhel5 mysql]# cp support-files/my-medium.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中


(3)创建系统数据库的表
[root@ rhel5 mysql]# cd /usr/local/mysql
[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql

(4)设置环境变量
[root@ rhel5~]# vi /root/.bash_profile

在PATH=$PATH:$HOME/bin添加参数为:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

[root@ rhel5~]#source /root/.bash_profile

(5)手动启动mysql
[root@ rhel5~]# cd /usr/local/mysql
[root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql &   //如果启动错误,则执行下面语句
-----------------------------------------------------------------------------

[root@ rhel5 mysql]# ./bin/mysqld_safe --user=root &   //启动MySQL,但不能停止


启动日志写在此文件下:/usr/local/mysql/data/localhost.err

关闭MySQL服务

[root@ rhel5 mysql]# mysqladmin -u root -p password  //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
(6)另一种简单的启动mysql的方法(mysql已经被添加到系统服务中)
[root@ rhel5 mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
[root@ rhel5~]# service mysqld start
[root@ rhel5~]# service mysqld stop
[root@ rhel5~]#service mysqld restart如果上述命令出现:./bin/mysqld_safe --user=root &   方式启动的必须修改 mysqld的脚本[root@localhost mysql]# vim /etc/init.d/mysqld找到start()函数 找到 语句: $bindir/mysqld_safe --user=root --添加这个字段[root@localhost mysql]# service mysqld start
Starting MySQL.. [ OK ]

(7)修改MySQL的root用户的密码以及打开远程连接
[root@ rhel5~]# mysql -u root mysql

mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。
mysql>update user set Password = password('xxxxxx') where User='root';
mysql>select Host,User,Password  from user where User='root';
mysql>flush privileges;
mysql>exit

重新登录:mysql -u root -p

若还不能进行远程连接,则关闭防火墙
[root@ rhel5~]# /etc/rc.d/init.d/iptables stop

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: