用户名/密码
mysql/mysql
一、安装mysql: 位置位于 /data/mysql
如果遇到依赖,无法删除,使用 rpm -e --nodeps <包的名字> 不检查依赖,直接删除rpm包
--1.0 查看linux系统版本、环境-------------------------------------------------------
[root@kangvcar ~]# cat /etc/redhat-release //查看系统的版本
[root@orcl bayaim]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
#安装环境
[root@linux1 Mysql_src]# cat /etc/issue
防火墙 chkconfig iptables off
SELINUX
gedit /etc/sysconfig/selinux
(本来是:SELINUXTYPE=targeted )
SELINUX=disabled
重启reboot
关闭---快照
[root@ums-data mysql]# setenforce 0
setenforce: SELinux is disabled
[root@ums-data mysql]# getenforce
Disabled
[root@ums-data mysql]#
---2.0 安装CMAKE-------------------------------------------------------------
[root@ums-data /]# yum install gcc
[root@ums-data /]# yum install ncurses-devel
[root@ums-data /]# tar -zxvf cmake-2.8.5.tar.gz
[root@ums-data /]# cd cmake-2.8.5
[root@ums-data /]# ./configure
[root@UMS-DATA-SLAVE cmake-2.8.5]# make
[root@UMS-DATA-SLAVE cmake-2.8.5]# make install
---3.0-配置 YUM--------------------------------------------------------------
[root@ums-data /]# vi /etc/resolv.conf
nameserver 114.114.114.114 (在结尾加上)
---CentOS 6
[root@ums-data /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@ums-data /]# yum makecache --生成缓存
---4.0-创建mysql用户及用户组------------------------------------------------------------
[root@ rhel5~]# groupadd mysql
创建mysql的安装目录及数据库存放目录
useradd -d /home/mysql -m mysql
passwd mysql
[root@bayaim rpm-gpg]# id mysql
uid=987(mysql) gid=1001(mysql) 组=1001(mysql)
如果有,请修改:
[root@tsxs bin]# usermod -s /bin/sh -d /usr/local/mysql -g mysql mysql
输入密码mysql
chown -R mysql:mysql /home/mysql
chmod 755 /home/mysql
[root@ rhel5~]# mkdir -p /usr/local/mysql //安装mysql
[root@ rhel5~]# chown -R mysql.mysql /usr/local/mysql/
[root@ rhel5~]# mkdir -p /data/mysql //存放数据库
[root@bayaim bay]# mkdir -p /usr/local/mysql/scripts
[root@ rhel5~]# chown -R mysql.mysql /data/
[root@ rhel5~]# chown -R mysql.mysql /data/*
[root@UMS-DATA-SLAVE data]# cd /bai/
[root@ums-data bai]# tar -zxvf mysql-5.7.22.tar.gz
[root@UMS-DATA-SLAVE bai]# cd mysql-5.7.22
[root@UMS-DATA-SLAVE mysql-5.7.22]# ll
---5.0-源码编译mysql------------------------------------------------------------
mysql软件目录: -DCMAKE_INSTALL_PREFIX
mysql数据目录: -DMYSQL_DATADIR
[root@UMS-DATA-SLAVE mysql-5.7.22]# time cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=/usr/local/boost -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
一定记得无报错,才行!!!
[root@UMS-DATA-SLAVE mysql-5.6.16]# make
[root@UMS-DATA-SLAVE mysql-5.6.16]# make install
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++问题1: 《mysql5.7 必须安装2.9以上的cmake》++++++++
bash: cmake: 未找到命令...
tar -xzvf cmake-2.6.4.tar.gz
cd cmake-2.6.4
依次执行:
./bootstrap
make
make install
++++++++问题2:+++++++++++++
mysql5.7.28 安装过程 报错CMake Error at cmake/boost.cmake:81 (MESSAGE)
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
问题描述:高版本mysql需要boots库的安装才可以正常运行
解决办法:
1.在/usr/local下创建一个名为boost的文件夹
mkdir -p /usr/local/boost
2.进入这个新创建的文件夹然后下载boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
3.解压
tar -xvzf boost_1_59_0.tar.gz
4.继续cmake,添加上红色部分
即安装后运行:
因为boost并不需要我们安装,只需要放到指定的目录,在安装mysql的时候,指定boost目录即可,再次我将解压后的文件移动到/usr/local/boost目录中。
5.然后回到mysql安装。 只需要加上:-DWITH_BOOST=/usr/local/boost 即可
++++++++问题3:++++++++++
CMake Error at cmake/readline.cmake:83(MESSAGE):Curses library not found.
解决方法:
安装ncurses-devel:
yum -y install ncurses-devel(Debian/Ubuntu需安装libncurses5-dev)
删除mysql解压目录 , 重新执行编译mysql安装
make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc_setops.cc.o] 错误 4
++++++++问题4:+++++++++++
make && make install 命令 执行到49% 报 c++: 编译器内部错误:已杀死(程序 cc1plus)
内存不足,mysql 5.5以上版本编译需要1G以上内存,可以编译安装mysql5.5
解决方法: linux dd 增加swap 内存
++++++++问题5:++++++++++
[root@bayaim mysql-5.7.22]# yum install ncurses-devel
Warning: Bison executable not found in PATH
-- Configuring done
-- Generating done
-- Build files have been written to: /software/mysql-5.5.11
[root@bayaim mysql-5.7.22]# yum install bison
继续安装:
[root@bayaim mysql-5.7.22]# make && make install -- 这个安装时间真是JB长。大约半小时呢。XX
---6.0-添加环境变量------------------------------------------------------------
方法一:
[root@ums-data support-files]# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@ rhel5~]#source /root/.bash_profile
方法二:
[root@query-db data]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
[root@query-db data]# source /etc/profile
---7.0-建立多实例目录------------------------------------------------------------
[root@UMS-DATA-SLAVE scripts]# pwd
/usr/local/mysql/scripts ---------这个目录是 make install 系统自动时候建立的
[root@query-db data]# mkdir -p /data/{mysql3306,mysql3307}
[root@query-db data]# ll
[root@query-db data]# mkdir /data/mysql3306/{log,tmp} ##千万不要建/data/ 听网上人瞎写
更改目录权限
[root@query-db data]# chown -R mysql:mysql /usr/local/mysql/
[root@query-db data]# chown -R mysql:mysql /data/
5.7新特性
cp /etc/my.cnf /data/mysql3306/my3306.cnf
cp /etc/my.cnf /data/mysql3307/my3307.cnf
---先,简单的改改---3307同3306---
[root@orcl mysql3306]# cat my3306.cnf
[mysqld]
port=3307
server-id=3307
basedir=/use/local/mysql
datadir=/data/mysql3307/data
socket=/data/mysql3307/mysql.sock
user=mysql
#log_long_format
binlog-format =row
log-bin =/data/mysql3307/log/mysql-bin
relay-log =/data/mysql3307/log/relay-bin
relay-log-info-file = /data/mysql3307/log/relay-log.info
tmpdir = /data/mysql3307/tmp
innodb_file_per_table = ON
skip_name_resolve = ON
skip_name_resolve = 1
skip-external-locking
max_connections = 400
max_connect_errors = 1000
slow_query_log = 1
slow_query_log_file =/data/mysql3307/log/slow.log
long_query_time=1
log-error = /data/mysql3307/log/error.log
symbolic-links=0
--8.0-安装数据库------------------------------------------------------------
--8.1-初始化数据库
[root@orcl bin]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-04-24T05:24:19.801232Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-24T05:24:23.219167Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-24T05:24:23.660821Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-24T05:24:23.764033Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 387d7210-6651-11e9-8685-000c29d26be0.
2019-04-24T05:24:23.788461Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-24T05:24:23.789327Z 1 [Note] A temporary password is generated for root@localhost: )zTtct*FO8zq
注意:所以要把data directory文件删除掉再执行,如果删除目录下的文件还是报同样的错,可以试试把目录删除掉,再创建一个,然后授权:
--8.2-初始化3306数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3306/data --defaults-file=/data/mysql3306/my3306.cnf
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3307/data --defaults-file=/data/mysql3306/my3306.cnf
注意:1.每次执行都会生成 data/ 文件夹,如果中途失败,就要手动删除!!
2.这一步执行完,/data/mysql3307/data 下就生成数据库文件了。
--defaults-file="/data/mysql3306/my3306.cnf"
--9.0-启动mysql数据库------------------------------------------------------------
[root@ rhel5 mysql]#/usr/local/mysql/bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止
或
cp /data/mysql/installdir/support-files/mysql.server /etc/init.d/mysqld
[root@orcl mysql3306]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql3306/my3306.cnf --user=mysql & //启动MySQL,但不能停止
[root@orcl mysql3307]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql3307/my3307.cnf --user=mysql & //启动MySQL,但不能停止
2019-04-24T06:16:42.991755Z mysqld_safe error: log-error set to '/data/mysql3306/my3306_err.log', however file don't exists. Create writable for user 'mysql'.
注意:日志文件必须先建!!!
[root@orcl mysql3307]# touch /data/mysql3307/my3306err.log
[root@orcl mysql3307]# touch /data/mysql3307/my3307err.log
[root@query-db data]# chown -R mysql:mysql /data/mysql3306/my3306.cnf ## 否则下面启动mysql服务会报错;
[root@query-db data]# chown -R mysql:mysql /data/mysql3306/my3307.cnf ## 否则下面启动mysql服务会报错;
[root@query-db data]# chown -R mysql:mysql /usr/local/mysql/
[root@query-db data]# chown -R mysql:mysql /data/
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql3306/my3306.cnf --user=mysql &
mysql --socket=/data/mysql3306/mysql.sock -uroot -proot
回车,直接进去mysql
创建自动启动文件
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld3306 ---增加mysqld 服务
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld3307
# chmod 755 /etc/rc.d/init.d/mysqld3306
# chmod 755 /etc/rc.d/init.d/mysqld3307
# vi /etc/rc.d/init.d/mysqld3306 #编辑 (3306,3307同理)
basedir=/usr/local/mysql #MySQL程序安装路径
datadir=/data/mysql3306/data #MySQl数据库存放目录
修改(注意格式 空格和缩进 不要动)
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
变成
$bindir/mysqld_safe --defaults-file="$datadir/my.cnf" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
---bayaim:我是这个=样改的
--defaults-file="/data/mysql3307/my3307.cnf"
关闭MySQL服务
[root@ rhel5 mysql]# mysqladmin -u root -p shutdown //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld3306
#复制脚本 :
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306 ---增加mysqld 服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307 ---增加mysqld 服务
#增加可执行权限 :
[root@orcl init.d]# chmod +x /etc/init.d/mysqld3306
[root@orcl init.d]# chmod +x /etc/init.d/mysqld3307
#增加至sysV服务 :
[root@orcl init.d]# chkconfig --add mysqld3306
[root@orcl init.d]# chkconfig --add mysqld3307
#开机自启动:
[root@orcl init.d]# chkconfig mysqld3306 on
[root@orcl init.d]# chkconfig mysqld3307 on
#启动mysql服务:
[root@orcl init.d]# service mysqld3306 start
[root@orcl init.d]# service mysqld3307 start
#查看启动的mysql进程:
[root@orcl init.d]# netstat -aux|grep mysql
[root@orcl init.d]# ps -ef|grep mysql
[root@query-db init.d]# vi /etc/rc.d/init.d/mysqld3307
[root@query-db init.d]# service mysqld3307 restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
--10.0-修改mysql密码------------------------------------------------------------
--10.1-登录
修改MySQL的root用户的密码以及打开远程连接
[root@UMS-DATA-SLAVE mysql]# mysql -uroot -p
Enter password:
回车
直接进去
--10.2-修改密码
MySQL5.7 加强了安全保障,以上意思是密码不符合安全策略要求,我们输入一个8位或以上长度,复杂一点的密码,比如:
mysql>use mysql;
mysql>desc user;
mysql>GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'rootBPY123.#' WITH GRANT OPTION;
mysql>update mysql.user set authentication_string=password('rootBPY123.#') where user='root' ;
删除空用户
mysql>DELETE FROM mysql.user WHERE user='';
mysql>flush privileges;
mysql>exit
--10.3-重新登录mysql------------------------------------------------------------
mysql --socket=/data/mysql3306/mysql.sock -uroot -prootBPY123.#
mysql --socket=/data/mysql3307/mysql.sock -uroot -prootBPY123.#
导入数据:
mysql> source /bayaim/bai_all_12.sql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| activity |
| dev01_miluo |
| disconf |
| jinfensc |
| maiya_licai |
| myjf_jobplatform |
| myjf_jobplatfrom |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
12 rows in set (0.00 sec)
mysql>
mysql> use jinfensc
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-------------------------------+
| Tables_in_jinfensc |
+-------------------------------+
| checksums |
| etl |
| etl_bi |
| etl_bi20160421 |
| etl_bi20160630 |
| etl_bi_all |
| fundcoupongive |
若还不能进行远程连接,则关闭防火墙
[root@ rhel5~]# /etc/rc.d/init.d/iptables stop
[root@ums-data-bak mysql]# service iptables stop
防火墙
[root@ums-data mysql]# chkconfig iptables off
[root@ums-data mysql]# iptables -F (清空防火墙默认规则)
[root@ums-data mysql]# systemctl stop firewalld.service (停止防火墙,这是CentOS7的命令)
[root@ums-data mysql]# systemctl disable firewalld //禁止开机启动
查看端口:
[root@ums-data mysql]# netstat -nutlp | grep 330
[root@ums-data mysql]# mysql -uroot -p -h192.168.66.143 -P3306
---------------------------
每次登陆 不需要密码登陆:
[root@oradata ~]# mysql_config_editor set --login-path=client --host=localhost --user=root --password --socket=/mysql/mysql3308/mysql3308.sock
[root@oradata ~]# pwd
/root
[root@oradata ~]# cat .mylogin.cnf
然后就可以无密码登陆了:
[root@oradata ~]# mysql --login-path=client