CentOS 下 MySQL 5.7 编译安装

MySQL5.7主要特性:

1—更好的性能:对于多核CPU、固态硬盘、锁有着更好的优化,每秒100W QPS已再也不是MySQL的追求,下个版本可否上200W QPS才是吾等用户更关心的mysql

2—更好的InnoDB存储引擎c++

3—更为健壮的复制功能:复制带来了数据彻底不丢失的方案,传统金融客户也能够选择使用MySQL数据库。此外,GTID在线平滑升级也变得可能sql

4—更好的优化器:优化器代码重构的意义将在这个版本及之后的版本中带来巨大的改进,Oracle官方正在解决MySQL以前最大的难题数据库

5—原生JSON类型的支持vim

6—更好的地理信息服务支持:InnoDB原生支持地理位置类型,支持GeoJSON,GeoHash特性bash

7—新增sys库:之后这会是DBA访问最频繁的库微信

##安装依赖包 yum -y install gcc gcc-c++ ncurses ncurses-devel cmake ##下载相应源码包 cd /home/quant_group/mysql #cd /your/download/path wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.11.tar.gzide

文件目录建立

mkdir -p /home/quant_group/mysql/3306/data
mkdir -p /home/quant_group/mysql/3306/tmp
mkdir -p /home/quant_group/mysql/3306/log

咱们在这里是把mysql安装到/home目录下,没有安装到/下,防止系统出问题丢失数据

##添加mysql用户 useradd -M -s /sbin/nologin mysql ##预编译 tar xzf boost_1_59_0.tar.gz tar xzf mysql-5.7.11.tar.gz cd mysql-5.7.11 cmake -DCMAKE_INSTALL_PREFIX=/home/quant_group/mysql/3306
-DMYSQL_DATADIR=/home/quant_group/mysql/3306/data
-DWITH_BOOST=/home/quant_group/mysql/boost_1_59_0
-DSYSCONFDIR=/home/quant_group/mysql
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DENABLED_LOCAL_INFILE=1
-DENABLE_DTRACE=0
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DWITH_EMBEDDED_SERVER=1 ##编译安装 make make install ##启动脚本,设置开机自启动 /bin/cp /home/quant_group/mysql/3306/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on ##/etc/my.cnf,仅供参考 [mysqld] basedir = /home/quant_group/mysql/3306 datadir = /home/quant_group/mysql/3306/data tmpdir = /home/quant_group/mysql/3306/tmp pid-file = /home/quant_group/mysql/3306/data/my.pid port = 3306性能

default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2

explicit_defaults_for_timestamp = true
character-set-client-handshake = FALSE
character_set_server = utf8
skip-name-resolve
max_connect_errors = 1000000
max_allowed_packet = 1G

connect_timeout = 3600
wait_timeout = 3600
interactive_timeout = 3600
innodb_lock_wait_timeout = 10
slave-skip-errors  = 1032,1062
log-error = /home/quant_group/mysql/3306/log/error.log

slow_query_log = on
slow_query_log_file = /home/quant_group/mysql/3306/log/slow-query-log.log
long_query_time = 1
log-queries-not-using-indexes
log-slow-admin-statements
log-slow-slave-statements

server-id = 100
log-bin = log-bin
binlog-format = ROW

##初始化数据库 chown -R mysql:mysql /home/quant_group/mysql/3306/ cd /home/quant_group/mysql/3306/bin ./mysql_install_db --user=mysql --basedir=/home/quant_group/mysql/3306 --datadir=/home/quant_group/mysql/3306/data ###注: 以前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃优化

"--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码

--datadir目标目录下不能有数据文件

##启动 数据库 service mysqld start # 启动不了多是权限问题,把 mysql/3306下面都赋予mysql用户权限就好啦 ##查看 密码 view /root/.mysql_secret ##登陆 数据库 mysql -uroot -p'.U,tH2Cf3vRj' #这边密码要加引号,要么然的话存在转义问题 若是提示 bash: mysql: command not found 那么vim /root/.bash_profile 将mysql 的命令加进去 好比: # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs # PATH=$PATH:$HOME/bin #修改前 PATH=$PATH:$HOME/bin:/usr/local/mysql/bin #修改后 export PATH 而后 source /root/.bash_profile

而后修改密码,好比修改root用户的新密码为123456
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

##如何删除数据库 yum remove mysql mysql-server mysql-libs mysql-server;

find / -name mysql 将找到的相关东西delete掉;

rpm -qa|grep mysql(查询出来的东东yum remove掉)

建立用户

The create user command:

    create user test identified by '123456';
    上面创建的用户能够在任何地方登录。

    若是要限制在固定地址登录,好比localhost 登录:
    create user test@登陆主机 identified by '123456';

grant:
    grant all privileges on *.* to test@登陆主机
    grant select,insert,update,delete on *.* to test@"%" Identified by "123456";
    格式:grant select on 数据库.* to 用户名@登陆主机 identified by "密码"

修改密码:
    grant all privileges on 数据库.* to test@登陆主机 identified by '654321'; 
flush:
    flush privileges; 
查看用户信息:
    select host,user from mysql.user;

###donation: 若有捐赠意向的朋友,请捐赠到支付宝帐号:qdcccc@gmail.com 帐户名:杨春炼

###ask for help: 如需帮助,请加QQ:1028750558或微信:lian-ye

相关文章
相关标签/搜索