1、yum -y install lrzsz ---先安装上传文件用的工具,命令行里直接输入rz即可在本地上传文件
2、上传完成后,将文件解压,解压后的文件放在/usr/local/下,并建立软连接
建立软连接的目的是:为了方便版本控制
3、接下来按照mysql安装步骤的操作
/usr/local/mysql/INSTALL-BINARY
以下是该文件中的安装步骤
cat /usr/local/mysql/INSTALL-BINARY
.....
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
.....
4、增加msyql的组、用户,建立软连接后,把mysql数据库目录中文件属主、属组修改,按3中的步骤完成
修改后,应该是除了data是mysql mysql 其他全是root mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# ll
总用量 156
drwxr-xr-x. 2 root mysql 4096 2月 15 13:49 bin
-rw-r--r--. 1 root mysql 17987 9月 18 2015 COPYING
drwxr-xr-x. 5 mysql mysql 192 2月 15 13:57 data
drwxr-xr-x. 2 root mysql 55 2月 15 13:49 docs
drwxr-xr-x. 3 root mysql 4096 2月 15 13:49 include
-rw-r--r--. 1 root mysql 105656 9月 18 2015 INSTALL-BINARY
drwxr-xr-x. 3 root mysql 4096 2月 15 13:48 lib
drwxr-xr-x. 4 root mysql 30 2月 15 13:49 man
-rw-r--r--. 1 root root 943 2月 15 13:51 my.cnf
drwxr-xr-x. 10 root mysql 4096 2月 15 13:49 mysql-test
-rw-r--r--. 1 root mysql 2496 9月 18 2015 README
drwxr-xr-x. 2 root mysql 30 2月 15 13:48 scripts
drwxr-xr-x. 28 root mysql 4096 2月 15 13:48 share
drwxr-xr-x. 4 root mysql 4096 2月 15 13:49 sql-bench
drwxr-xr-x. 2 root mysql 136 2月 15 13:48 support-files
因为Linux自带的Mariadb,会有/etc/my.cnf文件,但配置不对,可能会导致初始化有问题,所以先进行如下操作:
mv /etc/my.cnf /etc/my.cnf.old
5、接下来进行数据库初始化操作,但是在初始化的时候报了个错,少了一个依赖包,解决如下:
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
[root@localhost mysql]# yum -y install autoconf
6、安装完依赖包后,进行初始化,初始化过程不应该有error信息,检验是否初始化成功,可以查看mysql数据目录是否有相应的数据文件生成
[root@localhost mysql]# ll data
总用量 110600
-rw-rw----. 1 mysql mysql 12582912 2月 15 13:51 ibdata1
-rw-rw----. 1 mysql mysql 50331648 2月 15 13:51 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 2月 15 13:51 ib_logfile1
drwx------. 2 mysql mysql 4096 2月 15 13:51 mysql
drwx------. 2 mysql mysql 4096 2月 15 13:51 performance_schema
drwxr-xr-x. 2 mysql mysql 20 2月 15 13:48 test
7、初始化完成后,启动数据库
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &
[1] 9283
[root@localhost mysql]# 200215 13:55:05 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
200215 13:55:05 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# ps -ef | grep mysql
root 9216 9107 0 13:50 pts/2 00:00:00 less /usr/local/mysql/INSTALL-BINARY
root 9283 8618 0 13:55 pts/1 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql 9373 9283 1 13:55 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root 9396 8618 0 13:55 pts/1 00:00:00 grep --color=auto mysql
通过mysql_safe启动进程,mysql_safe是一个守护进程,在mysql进程被 Kill掉后,会重启Mysql进程,如下所示:
[root@localhost mysql]# kill -9 9373
[root@localhost mysql]# ./bin/mysqld_safe: 行 166: 9373 已杀死 nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid < /dev/null >> /usr/local/mysql/data/localhost.localdomain.err 2>&1
200215 13:57:52 mysqld_safe Number of processes running now: 0
200215 13:57:52 mysqld_safe mysqld restarted
8、不用守护进程mysql_safe,用/usr/local/mysql/bin/mysqld启动进程,用mysqld启动进程,没有了守护进程的存在,在mysql进程宕掉的时候,不会自动重启
[root@localhost mysql]# ./bin/mysqld --user=mysql &
[1] 10387
[root@localhost mysql]# 2020-02-15 17:30:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-15 17:30:43 0 [Note] ./bin/mysqld (mysqld 5.6.27) starting as process 10387 ...
2020-02-15 17:30:43 10387 [Note] Plugin 'FEDERATED' is disabled.
2020-02-15 17:30:43 10387 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-02-15 17:30:43 10387 [Note] InnoDB: The InnoDB memory heap is disabled
2020-02-15 17:30:43 10387 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-02-15 17:30:43 10387 [Note] InnoDB: Memory barrier is not used
2020-02-15 17:30:43 10387 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-02-15 17:30:43 10387 [Note] InnoDB: Using Linux native AIO
2020-02-15 17:30:43 10387 [Note] InnoDB: Using CPU crc32 instructions
2020-02-15 17:30:43 10387 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-02-15 17:30:43 10387 [Note] InnoDB: Completed initialization of buffer pool
2020-02-15 17:30:43 10387 [Note] InnoDB: Highest supported file format is Barracuda.
2020-02-15 17:30:43 10387 [Note] InnoDB: 128 rollback segment(s) are active.
2020-02-15 17:30:43 10387 [Note] InnoDB: Waiting for purge to start
2020-02-15 17:30:43 10387 [Note] InnoDB: 5.6.27 started; log sequence number 1626017
2020-02-15 17:30:43 10387 [Note] Server hostname (bind-address): '*'; port: 3306
2020-02-15 17:30:43 10387 [Note] IPv6 is available.
2020-02-15 17:30:43 10387 [Note] - '::' resolves to '::';
2020-02-15 17:30:43 10387 [Note] Server socket created on IP: '::'.
2020-02-15 17:30:43 10387 [Note] Event Scheduler: Loaded 0 events
2020-02-15 17:30:43 10387 [Note] ./bin/mysqld: ready for connections.
Version: '5.6.27' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
[root@localhost mysql]#
9、将suportfiles里的mysql.server拷贝到/etc/init.d/下
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# ps -ef | grep mysql
root 9216 9107 0 13:50 pts/2 00:00:00 less /usr/local/mysql/INSTALL-BINARY
mysql 10387 8618 0 17:30 pts/1 00:00:01 ./bin/mysqld --user=mysql
root 10437 8618 0 17:53 pts/1 00:00:00 grep --color=auto mysql
[root@localhost mysql]# kill -9 10387
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[1]+ 已杀死 ./bin/mysqld --user=mysql
[root@localhost mysql]# ps -ef | grep mysql
root 9216 9107 0 13:50 pts/2 00:00:00 less /usr/local/mysql/INSTALL-BINARY
root 10443 1 0 17:54 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql 10544 10443 3 17:54 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root 10571 8618 0 17:54 pts/1 00:00:00 grep --color=auto mysql
[root@localhost mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost mysql]# ps -ef | grep mysql
root 9216 9107 0 13:50 pts/2 00:00:00 less /usr/local/mysql/INSTALL-BINARY
root 10588 8618 0 17:55 pts/1 00:00:00 grep --color=auto mysql
[root@localhost mysql]#
10、添加Mysql进程开机自启动
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost 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:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
rhnsd 0:关 1:关 2:开 3:开 4:开 5:开 6:关
因为将启动脚本添加到/etc/init.d/下 了,所以可以添加开机自启动
11、redhat已经有一个etc/my.cnf文件了,即mysql的配置文件,在mysql初始化的时候,会 以这个文件里的内容去初始化,如果按照默认的my.cnf去初始化,会有报错。以前经常遇到过这种情况,报错先不截图了。
实际生产环境中,把安装目录和数据目录分开放,一个独立的盘用来放数据 文件,还有一些其它的参数,比如innodb,redo,undo等(undo参数完不能改,redo还可以改---应该在mysql运行时进行修改,姜诚绒没有说)相关的参数,innodb_log_file_size=4G(在数据目录中会有两个文件生成,轮回覆盖的写)一般建议生产上按这个数值来设置,mysql默认的是48M(华夏用的就是48M),在5.5及以前版本中,这个参数设置大的时候,会有Bug,在恢复的时候会非常的缓慢,在5.6及以后的版本中修复了这个问题,恢复起来还是比较快的。其它参数可以看姜诚绒的my.cnf,下边会帖上来。
12、假如重新安装mysql时,只要删除初始化后生成的数据文件(在数据目录中的所有文件),删除,可以通过更换压缩包,更换软连接操作来换版本。再有就是配置文件my.cnf,可以没有,也有正常启动,但是不能有与mysql不匹配的配置文件存在,那样在初始化和启动的时候都会报错,初始化就报错,更不用说去启动了。
13、