声明:
如果您有更好的技术与作者分享,或者商业合作;请访问作者个人网站 http://www.esqabc.com/view/message.html 留言给作者。
如果该案例触犯您的专利,请在这里:http://www.esqabc.com/view/message.html 留言给作者说明原由,作者一经查实,马上删除。
Linux添加防火墙、iptables的安装和配置
请访问地址:https://www.cnblogs.com/lemon-flm/p/7608029.html
(1)下载安装包:
5.7.26
[root@esqabc tools]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
5.6.44
[root@esqabc tools]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
(2)把数据库文件拷贝到任意目录
[root@esqabc ~]# cd /home/tools/
[root@esqabc tools]# cp mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz /usr/local/
(3)编辑配置文件:my.cnf
[root@esqabc ~]# vim /etc/my.cnf
把以下的内容拷贝进去:
#数据库安装文件目录
basedir = /usr/local/mysql
#数据库数据目录
datadir = /usr/data/mysql
socket = /tmp/mysql.sock
#数据库日志目录
log-error = /usr/data/mysql/error.log
pid-file = /usr/data/mysql/mysql.pid
user = mysql
tmpdir =/tmp
lower_case_table_names=1
进入目录(/var/log/):
[root@esqabc ~]# cd /var/log/
创建文件夹:mariadb
[root@esqabc log]# mkdir mariadb
进入目录:/var/log/mariadb/
[root@esqabc ~]# cd /var/log/mariadb
创建文件:mariadb.log
[root@esqabc mariadb]# touch mariadb.log
(5)创建数据库存放目录
创建文件夹用来存放数据库data
[root@esqabc ~]# cd /usr
[root@esqabc ~]# mkdir data
[root@esqabc ~]# cd /usr/data/
[root@esqabc data]# mkdir mysql
(1)进入到数据库文件目录:cd /usr/local
[root@esqabc ~]# cd /usr/local
(2) 执行解压安装包:
[root@esqabc local]# tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
重命名
[root@esqabc local]# mv /usr/local/mysql-5.6.44-linux-glibc2.12-x86_64 /usr/local/mysql
(3)添加系统mysql组和mysql用户:
[root@esqabc ~]# groupadd mysql
[root@esqabc ~]# useradd -r -g mysql mysql
(4)进入安装mysql软件目录:
[root@esqabc ~]# cd /usr/local/mysql
(5)修改当前目录拥有者为mysql用户,
[root@esqabc mysql]# chown -R mysql:mysql ./
(6)安装数据库:
安装方式一:
[root@esqabc mysql]# ./scripts/mysql_install_db --user=mysql
安装方式二(推选):
[root@esqabc mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/data/mysql --pid-file=/usr/data/mysql/mysql.pid --tmpdir=/tmp
如果安装过程中出现最后面的错误:(请滚到最后面查看)
(8)修改当前目录拥有者为root用户
[root@esqabc mysql]# chown -R root:root ./
(9)修改当前data目录拥有者为mysql用户
[root@esqabc mysql] # chown -R mysql:mysql /usr/data
(10)启动mysql服务和添加开机启动mysql服务,添加开机启动
[root@esqabc ] # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
赋予可执行权限
[root@esqabc ] # chmod +x /etc/init.d/mysql
添加服务
[root@esqabc ] # chkconfig --add mysql
显示服务列表
[root@esqabc ] # chkconfig --list
(11)启动mysql服务:执行命令:service mysql start
[root@esqabc ] # service mysql start
如果出现下面的问题请滚到最后面查看
(1)#启动数据库命令:
[root@esqabc ~]# mysql service mysqld start
[root@esqabc ~]# service mysql start
(2)#关闭数据库命令:
[root@esqabc ~]# mysql service mysqld stop
[root@esqabc ~]# service mysql stop
(3)#查看数据库运行状态命令:
[root@esqabc ~]#service mysqld status
(4)给root账户开启远程登陆命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
1,查看数据库进程:
[root@esqabc ~]# ps -aux | grep mysql
2,输入登录命令:
[root@esqabc ~]# mysql -uroot -p
如果出现:-bash: mysql: command not found 请在最底下查找答案
3,修改root密码:
myslq > GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "1qaz2wsx!@";
4,开启远程访问:
mysql > grant all privileges on *.* to 'root'@'%'identified by '1qaz2wsx!@' with grant option;
出现: -bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决执行命令:
[root@esqabc ~]# yum -y install perl perl-devel
========================
出现: Installing MySQL system tables…./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决,执行命令:
[root@esqabc ~]# yum -y install libaio-devel
(由于默认是32位,所以要安装64的的,执行下面的命令)
[root@esqabc ~]# yum -y install numactl.x86_64
=========================
出现:FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
解决:执行命令:
[root@esqabc ~]# yum -y install autoconf
=======================
出现:FATAL ERROR: The parent directory for the data directory ‘/data/mysql’ does not exist.
If that path was really intended, please create that directory path and then
解决:请在跟目录新建文件夹:/data/mysql 执行命令:
[root@esqabc ~]# mkdir -p /data/mysql
====================
出现:Starting MySQL./usr/local/mysql/bin/mysqld_safe: line 183: 14957 Killed nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql – data dir=/data/mysql --plugin- dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/data/mysql/mysql.pid – socket=/tmp/mysql.sock < /dev/null > /dev/null 2>&1
ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).
解决:请在目录/usr/data/mysql 添加文件:mysql.pid 文件内容为空白
[root@esqabc ~]# cd /usr/data/mysql
[root@esqabc mysql]# touch mysql.pid
========================
出现:/usr/local/mysql/bin/mysqld_safe: line 183: 16497 Killed nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql – plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock < /dev/null > /dev/null 2>&1
解决:请在mysql配置文件(vim /etc/my.cnf)
加入配置:
key_buffer=16K
table_open_cache=4
query_cache_limit=256K
query_cache_size=4M
max_allowed_packet=1M
sort_buffer_size=64K
read_buffer_size=256K
thread_stack=64K
innodb_buffer_pool_size = 56M
==============================
出现:执行命令(mysql -uroot -p) -bash: mysql: command not found
解决:执行命令:
[root@esqabc ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin
手机留言请访问:http://www.esqabc.com