mysql编译安装及多实例安装的方法分享

发布时间:2020-08-11编辑:脚本学堂
本文介绍下,在linux中编译安装mysql及多实例安装的具体方法,有需要的朋友参考下。

本文介绍编译安装mysql 5.1的方法,供朋友们参考。

解压下载的安装包:
 

复制代码 代码示例:
#tar xvfz mysql-5.1.41.tar.gz
#cd mysql-5.1.41
#echo " CHOST="x86_64-pc-linux-gnu"  CFLAGS="-march=native -O3 -pipe -fomit-frame-pointer" CXX=gcc CXXFLAGS="-march=native -O3 -pipe -fomit-frame-pointer  -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --enable-assembler --with-libwrap=/usr/lib/ --with-charset=gbk --with-extra-charsets=gb2312,gbk,big5,latin1,utf8 --with-mysqld-user=mysql --with-big-tables --with-client-ldflags=-all-static --with-plugins=myisam,myisammrg,innobase,innodb_plugin,heap,csv,partition --with-mysqld-ldflags=-all-static" >configure.sh  // 编译

安装mysql:
 

复制代码 代码示例:

#chmod +x configure.sh
#./configure.sh

#make && make install

#groupadd mysql    /添加一个mysql组
#useradd -g mysql mysql  添加一个mysql用户到mysql组里

#cp support-files/my-medium.cnf /etc/my.cnf
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chmod 700 /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --level 345 mysqld on

#cd /usr/local/mysql
#bin/mysql_install_db --user=mysql

#chown -R root .
#chown -R mysql var
#chgrp -R mysql .

#bin/mysqld_safe --user=mysql &
#bin/mysqladmin -uroot -poldpwd password XXXX

下面介绍下 mysql 多实例安装的方法。

解压下载的安装包:
 

复制代码 代码示例:

#tar xvfz mysql-5.1.59.tar.gz

#cd mysql-5.1.59(Linux 5.3)
echo " CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --enable-assembler --with-libwrap=/usr/lib/ --with-charset=gbk --with-extra-charsets=gb2312,gbk,big5,latin1,utf8 --with-mysqld-user=mysql --with-big-tables --with-client-ldflags=-all-static --with-plugins=myisam,myisammrg,innobase,innodb_plugin,heap,csv,partition --with-mysqld-ldflags=-all-static" >configure1.sh

GCC4.4(Linux 6.2 )echo " CHOST="x86_64-pc-linux-gnu"  CFLAGS="-march=native -O3 -pipe -fomit-frame-pointer" CXX=gcc CXXFLAGS="-march=native -O3 -pipe -fomit-frame-pointer  -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --enable-assembler --with-libwrap=/usr/lib/ --with-charset=gbk --with-extra-charsets=gb2312,gbk,big5,latin1,utf8 --with-mysqld-user=mysql --with-big-tables --with-client-ldflags=-all-static --with-plugins=myisam,myisammrg,innobase,innodb_plugin,heap,csv,partition --with-mysqld-ldflags=-all-static" >configure.sh

注意:如果编译出现问题,请安装ncurses-devel-5.5-24.20060715.x86_64.rpm。
一般即可解决问题。

开始安装:
 

复制代码 代码示例:

#chmod +x configure.sh

#./configure.sh

#make && make install

创建mysql用户:
 

复制代码 代码示例:

#groupadd mysql
#useradd -g mysql mysql

#cp support-files/my-medium.cnf /etc/my.cnf
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#cp support-files/mysqld_multi.server /etc/rc.d/init.d/mysqld_multi

#chmod 700 /etc/init.d/mysqld
(忽略该步)#chkconfig --add mysqld
(忽略该步)#chkconfig --level 2345 mysqld off

#cd /usr/local/mysql

show variables like 'server_id';
 

查看server-id
 

复制代码 代码示例:
mysql> show variables like 'server_id';
 

手动修改server-id
 

复制代码 代码示例:
mysql> set global server_id=2; #此处的数值和my.cnf里设置的一样就行
mysql> slave start;

6)change master之后,查看slave的状态,发现slave_IO_running 为NO
注意:做完上述操作之后,记得重启mysql进程:
(初始化数据目录)
 

复制代码 代码示例:

#bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/var21001/
#bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/var21002/
#bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/var21003/

#bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/var(默认)

#chown -R root .
#chown -R mysql var21001/ var21002/ var21003/
#chgrp -R mysql .

#bin/mysqld_safe --user=mysql &

(到此安装完成)
 

复制代码 代码示例:

#bin/mysqladmin -uroot -poldpwd password 1qaz@WSX

grant shutdown on *.* to admin@localhost identified by 'pwd_shutdown';

FLUSH PRIVILEGES;

linux 客户端执行SQL命令:
 

复制代码 代码示例:

source /home/software/user_login.sql

grant all privileges on *.* to 'root'@'%' identified by '123456';

FLUSH PRIVILEGES;

GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'pwd_shutdown';

FLUSH PRIVILEGES;

drop user ''@'localhost.localdomain';
drop user ''@'localhost';
drop user root@localhost.localdomain;

GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'pwd_shutdown';

set password for root@'localhost' =password('1qaz@WSX');
set password for root@'127.0.0.1' =password('1qaz@WSX');
flush privileges;
//set password for root@'localhost' =password('XXX');
//set password for root@'127.0.0.1' =password('XXX');

主从权限增加:
 

复制代码 代码示例:
GRANT REPLICATION SLAVE ON *.* TO 'repsync'@'%' IDENTIFIED BY '*********';