Centos 6.4源码安装mysql-5.6.28.tar.gz教程
Bwz_Learning 人气:0mysql5.6.28安装教程分享
1、在安装MySQL-5.6.28.tar.gz前,先安装编译环境
2、编译安装mysql
2.1 添加用户
groupadd mysql useradd -g mysql mysql
2.2 编译安装
tar -zxvf mysql-5.6.28.tar.gz #默认情况下是安装在/usr/local/mysql cd mysql-5.6.28 cmake . -LH (使用默认属性编译) make && make install
2.3.1 编译参数的设定
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci;
2.3.2 完整版
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci;
2.4 改变mysql安装目录的所有者
chown -R mysql:mysql /usr/local/mysql #让mysql用户,具有写的权限(默认具有)
3、初始化数据库
cd /usr/local/mysql/scripts ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
4、将mysql的配置文件拷贝到/etc/my.cnf
#使用默认配置文件 cd /usr/local/mysql/support-files cp my-default.cnf /etc/my.cnf #修改配置文件,添加下面的内容 #socket适用于,通信的,一定要添加 #socket的位置和cmake时mysql的-DMYSQL_UNIX_ADDR=/tmp/mysql.sock的路径,socket的路径地址要和前面的地址一样(不然mysql服务不能正常启动.) basedir = /usr/local/mysql datadir = /usr/local/mysql/data pid-file = /usr/local/mysql/data/mysql.pid user = mysql socket= /tmp/mysql.sock
5、将mysql服务,添加到系统服务里面,并设置开启自启动
cd /usr/local/mysql/support-files #注册服务 cp mysql.server /etc/rc.d/init.d/mysql #让chkconfig管理mysql服务 chkconfig --add mysql #开机启动 chkconfig mysql on
6、启动Mysql服务
service mysql start #验证mysql启动成功 netstat -ant | grep 3306
7、配置mysql用户,修改root密码
Mysql启动成功后,root默认没有密码,我们需要设置root密码。
设置root密码之前,先设置PATH路径,以便能直接调用/usr/local/mysql/bin中的mysql等命令.
修改/etc/profile文件,在文件末尾加入
PATH=/usr/local/mysql/bin:$PATH export PATH
关闭文件,运行下面的命令,让配置立即生效
source /etc/profile
关于怎么修改root用户密码1:
#将'new-password'改成自己的密码 /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
关于怎么修改root用户密码2:
#要输入的密码,就是上面设置的密码 [root@VM_13_53_centos support-files]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.28 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
若要设置root用户可以远程访问,执行
#将下面的'password'改成自己的密码 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; mysql> flush privileges;
9、关闭防火墙,防止远程连接失败
1)重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2)立即生效
开启: service iptables start
关闭: service iptables stop
3)开放3306端口
vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT service iptables restart
10、改变编码,防止乱码
SHOW VARIABLES LIKE 'character%'
修改mysql的、etc/my.cnf文件
[client] default-character-set=utf8 [mysqld] character-set-server=utf8 [mysql] default-character-set=utf8
11、可能出现的错误
问题1:Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid).
解决:
修改/etc/my.cnf 添加socket的配置
问题2:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决:
新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。
ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock
12、参考的博客文章
13、Mysql的下载:http://pan.baidu.com/s/1jHXOzMe
加载全部内容