linux下用tar包安装mysql

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  添加用户

?
1
2
groupadd mysql
useradd -g mysql mysql

2.2  编译安装

?
1
2
3
4
5
tar -zxvf mysql-5.6.28. tar .gz
#默认情况下是安装在/usr/local/mysql
cd mysql-5.6.28
cmake . -LH (使用默认属性编译)
make && make install

 2.3.1 编译参数的设定

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 完整版

?
1
2
3
4
5
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安装目录的所有者

?
1
2
chown -R mysql:mysql /usr/local/mysql
#让mysql用户,具有写的权限(默认具有)

3、初始化数据库

?
1
2
cd /usr/local/mysql/scripts
. /mysql_install_db --user=mysql --basedir= /usr/local/mysql --datadir= /usr/local/mysql/data

4、将mysql的配置文件拷贝到/etc/my.cnf

?
1
2
3
4
5
6
7
8
9
10
11
#使用默认配置文件
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服务,添加到系统服务里面,并设置开启自启动

?
1
2
3
4
5
6
7
8
9
10
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服务

?
1
2
3
4
5
service mysql start
 
 
#验证mysql启动成功
netstat -ant | grep 3306

7、配置mysql用户,修改root密码
Mysql启动成功后,root默认没有密码,我们需要设置root密码。
设置root密码之前,先设置PATH路径,以便能直接调用/usr/local/mysql/bin中的mysql等命令.
修改/etc/profile文件,在文件末尾加入

?
1
2
PATH= /usr/local/mysql/bin :$PATH
export PATH

关闭文件,运行下面的命令,让配置立即生效
source /etc/profile 

关于怎么修改root用户密码1:

?
1
2
#将'new-password'改成自己的密码
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

关于怎么修改root用户密码2:

现在,参考博客,地址是http://www.jb51.net/article/102820.htm
使用root用户登录mysql:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#要输入的密码,就是上面设置的密码
[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用户可以远程访问,执行

?
1
2
3
#将下面的'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端口

?
1
2
3
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文件

?
1
2
3
4
5
6
7
8
[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位置。    

?
1
2
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、http://www.jb51.net/article/102799.htm

      2、http://www.jb51.net/article/102807.htm

13、Mysql的下载:https://pan.baidu.com/s/1jHXOzMe

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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值