用户名/密码
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/{mysql3308,mysql3309}
[root@query-db data]# ll
[root@query-db data]# mkdir /data/mysql3308/{log,tmp} ##千万不要建/data/ 听网上人瞎写
更改目录权限
[root@query-db data]# chown -R mysql:mysql /usr/local/mysql/
[root@query-db data]# chown -R mysql:mysql /data/
[root@query-db data]# chown -R mysql:mysql /etc/my.cnf
---先,简单的改改---3307同3306---
[root@orcl mysql3306]# cat my3306.cnf
--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-初始化3308/3309数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3308/data
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3309/data
注意:1.每次执行都会生成 data/ 文件夹,如果中途失败,就要手动删除!!
2.这一步执行完,/data/mysql3307/data 下就生成数据库文件了。
--defaults-file="/data/mysql3306/my3306.cnf"
修改my.cnf(在一个文件中修改即可)
[client]
port=3308
socket=/data/mysql3308/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /data/mysql/mysqld_multi.log
[mysqld]
user=mysql
basedir = /usr/local/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld3308]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/data/mysql3308/data
port=3308
server_id=3308
socket=/data/mysql3308/mysql3308.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql3308/log/slow.log
log-error = /data/mysql3308/log/error.log
binlog_format = row
log-bin = /data/mysql3308/log/mysql3308_bin
[mysqld3309]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/data/mysql3309/data
port=3309
server_id=3309
socket=/data/mysql3309/mysql3309.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql33079/log/slow.log
log-error = /data/mysql3309/log/error.log
binlog_format = row
log-bin = /data/mysql3309/log/mysql3309_bin
注意:这种方式,不需要建立log 日志。
7 创建自动启动文件
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld3306
[root@query-db init.d]# vi /etc/rc.d/init.d/mysqld3307
[root@query-db init.d]# service mysqld3307 restart
--9.0-启动mysql数据库------------------------------------------------------------
分配独立配置文件
#配置文件优先级,/etc/与basedir目录下不要存在my.cnf配置文件
/etc/my.cnf >basedir/my.cnf >datadir/my.cnf
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql3306/my3306.cnf --user=mysql & //启动MySQL,但不能停止
mysql --socket=/data/mysql3306/mysql.sock -uroot -proot
回车,直接进去mysql
2.14.mysqld_multi进行多实例管理
启动全部实例:[root@mysql ~]# /usr/local/mysql/bin/mysqld_multi start
关闭全部实例: [root@mysql ~]# /usr/local/mysql/bin/mysqld_multi report
查看全部实例状态:/usr/local/mysql/bin/mysqld_multi report
启动单个实例:/usr/local/mysql/bin/mysqld_multi start 3306
停止单个实例:/usr/local/mysql/bin/mysqld_multi stop 3306
查看单个实例状态:/usr/local/mysql/bin/mysqld_multi report 3306
[root@test4 ~]# /usr/local/mysql/bin/mysqld_multi --defaults-file=/etc/my.cnf start 3308
启动mysql服务器:./mysqld_multi --defaults-file=/etc/my.cnf start 3306-3307
关闭mysql服务器: mysqladmin shutdown
(2)启动多实例
[root@test4 ~]# /usr/local/mysql/bin/mysqld_multi --defaults-file=/etc/my.cnf start 3308
[root@test4 ~]# mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1,2,3
--------------------------------------------
[root@oradata mysql3308]# mysql -h127.0.0.1 -P 3308 -uroot -p
[root@oradata mysql3308]# mysql --socket=/data/mysql_3306/data/mysql_3306.sock
[root@oradata mysql3308]# mysql -S /data/mysql_3306/data/mysql_3306.sock
[root@query-db data]# mysql --socket=/data/mysql_3306/data/mysql_3306.sock -uroot -proot
[root@query-db data]# mysql --socket=/data/mysql_3307/data/mysql_3307.sock -uroot -proot
mysql --socket=/data/mysql3308/mysql3308.sock -uroot -p
mysql --socket=/data/mysql3308/mysql3308.sock -uroot -prootBPY123.#
mysql --socket=/data/mysql3309/mysql3309.sock -uroot -p
mysql --socket=/data/mysql3309/mysql3309.sock -uroot -prootBPY123.#
[root@orcl data]# mysql -h127.0.0.1 -P 3308 -uroot -p
[root@orcl data]# mysql --socket=/data/mysql3308/mysql3308.sock -uroot -prootBPY123.# -hlocalhost
修改3307实例密码:
# /usr/local/mysql/bin/mysqladmin -u root password 'root' -S /data/mysql_3308/data/mysql_3308.sock #设置管理员密码
5. 关闭mysql多实例方式
# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /data/mysql_3306/mysql_3306.sock shutdown
# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /data/mysql_3307/data/mysql_3307.sock shutdown
# /usr/local/mysql/bin/mysqladmin -u root -p -P 3308 -S /data/mysql_3308/data/mysql_3308.sock shutdown
[root@orcl data]# mysqladmin shutdown --socket=/data/mysql3308/mysql3308.sock -uroot -prootBPY123.# -hlocalhost
[root@orcl data]# mysqladmin shutdown --socket=/data/mysql3309/mysql3309.sock -uroot -prootBPY123.# -hlocalhost
或采用kill方式,或编
查看端口:
[root@oradata ~]# lsof -i :3306
[root@oradata ~]# netstat -lnt|grep 330
--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> select Host,User from user where User='root';
删除空用户
mysql>DELETE FROM mysql.user WHERE user='';
mysql>flush privileges;
mysql>exit