[iyunv@chy01 src]# uname -a
Linux chy01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
(首先区分linux系统为32还是64然后下载mysql包)
[iyunv@chy01 src]# wget http://mirrors.sohu.com/mysql/My ... bc2.5-x86_64.tar.gz
(下载二进制mysql包)
[iyunv@chy01 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
(解压mysql包)
[iyunv@chy01 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql (移动mysql到/usr/local/mysql下)
[iyunv@chy01 src]# cd /usr/local/mysql/ (进入此目录下)
[iyunv@chy01 mysql]# ls (进入后查看文件)
bin data include man README share support-files
COPYING docs lib mysql-test scripts sql-bench
[iyunv@chy01 mysql]# useradd -s /sbin/nologin -M mysql (增加mysql用户)
[iyunv@chy01 mysql]# mkdir -p /data/mysql
(创建data目录,此目录下存放的是数据库)
[iyunv@chy01 mysql]# useradd mysql (增加mysql用户)
[iyunv@chy01 mysql]# chown -R mysql /data/mysql 给这个mysql给权限
[iyunv@chy01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
(初始化时报了一个错误,解决方法如下
[iyunv@chy01 mysql]# yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64 2.145-3.el7 base
perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel
perl-Data-Dumper-Names.noarch 0.03-17.el7 epel
perl-XML-Dumper.noarch 0.81-17.el7 base
(模糊搜索perl 里面的dumper包)
[iyunv@chy01 mysql]# yum install -y perl-Data-Dumper.x86_64
(找到4个dumper包以后一个一个的测试,然后安装)
[iyunv@chy01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
(当再次编译时发现不报错就证明安装的dumper包是正确的)
[iyunv@chy01 mysql]# echo $?
0
(编译后马上用echo 测试,这个测试的前提是马上就要测试中间不要有任何的其它操作)
第二种方法是编译后查看有没有(如下的两个ok,如有就证明成功了)
OK
Filling help tables...2017-07-26 08:23:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-26 08:23:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-07-26 08:23:02 0 [Note] ./bin/mysqld (mysqld 5.6.35) starting as process 4652 ...
2017-07-26 08:23:02 4652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-07-26 08:23:02 4652 [Note] InnoDB: The InnoDB memory heap is disabled
2017-07-26 08:23:02 4652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-07-26 08:23:02 4652 [Note] InnoDB: Memory barrier is not used
2017-07-26 08:23:02 4652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-07-26 08:23:02 4652 [Note] InnoDB: Using Linux native AIO
2017-07-26 08:23:02 4652 [Note] InnoDB: Using CPU crc32 instructions
2017-07-26 08:23:02 4652 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-07-26 08:23:02 4652 [Note] InnoDB: Completed initialization of buffer pool
2017-07-26 08:23:02 4652 [Note] InnoDB: Highest supported file format is Barracuda.
2017-07-26 08:23:02 4652 [Note] InnoDB: 128 rollback segment(s) are active.
2017-07-26 08:23:02 4652 [Note] InnoDB: Waiting for purge to start
2017-07-26 08:23:02 4652 [Note] InnoDB: 5.6.35 started; log sequence number 1625977
2017-07-26 08:23:02 4652 [Note] Binlog end
2017-07-26 08:23:02 4652 [Note] InnoDB: FTS optimize thread exiting.
2017-07-26 08:23:02 4652 [Note] InnoDB: Starting shutdown...
2017-07-26 08:23:04 4652 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
[iyunv@chy01 mysql]# ls support-files/my-default.cnf
support-files/my-default.cnf
(如上是mysql的模板配置文件)
[iyunv@chy01 mysql]# cat /etc/my.cnf
(mysql的配置文件就是/etc/my.cnf,如果要更改此位置就需要在启动时指定文件)
[iyunv@chy01 mysql]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64
(系统下有一个默认的mysq是rpm安装的)
[iyunv@chy01 mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
(需要cp mysql配置文件到/etc/my.cnf下)
[iyunv@chy01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
(cp support-files/mysql.server这个到/etc/init.d/mysqld(这个里面配置启动脚本)
[iyunv@chy01 mysql]# vi /etc/init.d/mysqld (增加如下两行配置)
basedir=/usr/local/mysql(这里是mysql的主目录)
datadir=/data/mysql(这是mysql的数据库目录)
[iyunv@chy01 mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10902 7月 26 08:40 /etc/init.d/mysqld (查看权限是否为755)
[iyunv@chy01 mysql]# chkconfig --add mysqld(增加开机启动的选项)
[iyunv@chy01 mysql]# chkconfig --list
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[iyunv@chy01 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/chy01.err'.
. SUCCESS! (启动mysql第一种方法)
[iyunv@chy01 mysql]# service mysqld start
Starting MySQL. SUCCESS!
(启动mysql第二种方法)
[iyunv@chy01 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
(第三种用命令行启动)
[iyunv@chy01 mysql]# ps -aux |grep mysql
root 5570 0.0 0.1 113256 1584 pts/0 S 08:50 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
mysql 5673 0.2 29.7 973048 455708 pts/0 Sl 08:50 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/chy01.err --pid-file=/data/mysql/chy01.pid
root 5721 0.0 0.0 112664 976 pts/0 R+ 08:53 0:00 grep --color=auto mysql
[iyunv@chy01 mysql]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2053/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2875/master
tcp6 0 0 :::3306 :::* LISTEN 5673/mysqld
tcp6 0 0 :::22 :::* LISTEN 2053/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2875/master
(启动成功)
[iyunv@chy01 mysql]# killall mysqld
(关闭由命令行启动的方式)
登录mysql用户
[iyunv@chy01 mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile (需要做mysql的环境变量,如果不做环境变量不能使用mysq命令)
[iyunv@chy01 mysql]# tail -n1 /etc/profile(查看增加环境变量的文件)
export PATH=/usr/local/mysql/bin:$PATH
[iyunv@chy01 mysql]# source /etc/profile
[iyunv@chy01 mysql]# mysql -uroot (用root用户登录测试一下)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
wait_for_ready; return_value=$?
(找到这一行内容在$bindir/mysqld_safe 与--datadir="$datadir"中间增加一行--defaults-file="$conf")
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
(增加的意思是增加它的启动脚本)
这里启动时报错:
[iyunv@chy ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl): Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
[失败]
解决方法:
[iyunv@chy mariadb]# vim /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
user=mysql1(增加一行是因为我的用户是mysql1)