成都创新互联网站制作重庆分公司

MySQL安装方式

一、单实例_rpm
1、上传安装包
tar -xf MySQL-5.7.24-1.el6.x86_64.rpm-bundle.tar
2、检查是否安装

创新互联专业为企业提供台山网站建设、台山做网站、台山网站设计、台山网站制作等企业网站建设、网页设计与制作、台山企业网站模板建站服务,十余年台山做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

rpm -qa | grep -i mysql
rpm -qa | grep -i maria
若有安装 yum remove -y  包名
rm -fr /usr/lib/mysql
rm -fr /usr/include/mysql
rm -fr /etc/my.cnf
rm -fr /var/lib/mysql
rm -fr /usr/share/mysql
rm -fr /usr/local/mysql
find / -name mysql

3、安装MySQL

mkdir -p /home/mysql/{3306,3307}/{data,log}
chown -R mysql:mysql /home
chmod -R 755 /home
cd /home/mysql/
rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.24-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm

4、my.cnf

vi /etc/my.cnf
修改目录

5、初始化数据库

/usr/bin/mysql_install_db --user=mysql  --datadir=/home/mysql/3306/data 
cat /root/.mysql_secret

6、启动MySQL

cd /usr/bin/
/usr/bin/mysqld_safe  --defaults-file=/etc/my.cnf  --user=mysql  &

7、登录MySQL

mysql -uroot -p -S /home/mysql/3306/mysql.sock
SET PASSWORD=PASSWORD('root');
flush privileges;

8、关闭MySQL
/usr/bin/mysqladmin -uroot -proot -S /home/mysql/3306/mysql.sock shutdown
二、单实例_glibc
1、上传安装包

tar -xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64  /usr/local/mysql
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile
source /etc/profile

2、创建用户/目录

groupadd mysql
useradd -g mysql mysql
passwd mysql
mkdir -p /home/mysql/{3306,3307}/{data,log}
chown -R mysql:mysql /home
chmod -R 755 /home

3、my.cnf

vi /etc/my.cnf
[mysql]
socket=/home/mysql/3306/data/mysql.sock
port = 3306
[mysqld]
port = 3306
#skip-grant-tables
basedir=/usr/local/mysql 
datadir=/home/mysql/3306/data/
user=mysql 
log-error=/home/mysql/3306/log/resourcepool-0559.err 
pid-file=/home/mysql/3306/data/resourcepool-0559.pid
socket=/home/mysql/3306/data/mysql.sock
symbolic-links=0
server-id=102
log-bin=mysql-bin
binlog-ignore-db = mysql,information_schema
auto-increment-offset = 1
slave-skip-errors = all
#auto-increment-increment = 2
#default-storage-engine=MyISAM
binlog_format="MIXED"
log_bin_trust_function_creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
expire_logs_days = 7
event_scheduler=1
relay-log=relay-log

4、初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/3306/data
5、启动/关闭数据库

/usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf  --user=mysql  &
/usr/local/mysql/bin/mysqladmin -uroot -p -P3306 -S  /data/mysql/data/mysql.sock shutdown

三、多实例_glibc
1、安装依赖

vi /etc/yum.repos.d/yum.repo
文件内容改为如下:
[base]
name=Red Hat Enterprise Linux
baseurl=file:///media/Server  
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
yum install ncurses-devel -y
yum install libail-devel -y
yum install -y gcc

2、创建用户/目录

groupadd mysql
useradd -g mysql mysql
passwd mysql
mkdir -p /home/mysql/{3306,3307}/{data,log}
chown -R mysql:mysql /home
chmod -R 755 /home

3、解压安装

tar -xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64  /usr/local/mysql
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile
source /etc/profile
vi /etc/my.cnf
[client]  
port=3306  
socket=/tmp/mysql.sock  

[mysqld_multi]  
mysqld = /usr/local/mysql/bin/mysqld_safe  
mysqladmin = /usr/local/mysql/bin/mysqladmin  
log = /home/mysql/mysqld_multi.log  

[mysqld]  
user=mysql  
basedir = /usr/local/mysql  
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES  

[mysqld3306]  
mysqld=mysqld  
mysqladmin=mysqladmin  
datadir=/home/mysql/3306/data  
port=3306  
server_id=3306  
socket=/tmp/mysql_3306.sock  
log-output=file  
slow_query_log = 1  
long_query_time = 1  
slow_query_log_file = /home/mysql/3306/log/slow.log  
log-error = /home/mysql/3306/log/error_3306.log  
binlog_format = mixed  
log-bin = /home/mysql/3306/data/mysql3306_bin  

[mysqld3307]  
mysqld=mysqld  
mysqladmin=mysqladmin  
datadir=/home/mysql/3307/data  
port=3307  
server_id=3307  
socket=/tmp/mysql_3307.sock  
log-output=file  
slow_query_log = 1  
long_query_time = 1  
slow_query_log_file = /home/mysql/3307/log/slow.log  
log-error = /home/mysql/3307/log/error_3307.log  
binlog_format = mixed  
log-bin = /home/mysql/3306/data/mysql3307_bin

4、初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql
5、启动数据库
设置启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
6、mysqld_multi进行多实例管理

启动全部实例:/usr/local/mysql/bin/mysqld_multi start
查看全部实例状态:/usr/local/mysql/bin/mysqld_multi report 
启动单个实例:/usr/local/mysql/bin/mysqld_multi start 3306 
停止单个实例:/usr/local/mysql/bin/mysqladmin -u root -p -S /tmp/mysql_3306.sock shutdown
查看单个实例状态:/usr/local/mysql/bin/mysqld_multi report 3306
mysql -S /tmp/mysql_3306.sock -p
SET PASSWORD=PASSWORD('root');
flush privileges;

文章标题:MySQL安装方式
转载来源:http://cxhlcq.com/article/gehedh.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部