当前位置: 移动技术网 > IT编程>数据库>Mysql > Centos 6.4源码安装mysql-5.6.28.tar.gz教程

Centos 6.4源码安装mysql-5.6.28.tar.gz教程

2017年12月12日  | 移动技术网IT编程  | 我要评论

巧虎 宝宝版,xkt,碧血盐枭国语全集

mysql5.6.28安装教程分享

1、在安装mysql-5.6.28.tar.gz前,先安装编译环境

复制代码 代码如下:
yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
 

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用户登录mysql:

#要输入的密码,就是上面设置的密码 
[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、参考的博客文章

      1、

      2、

13、mysql的下载:https://pan.baidu.com/s/1jhxozme

精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 mysql5.6各版本安装教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网