一、卸载mariadb
[root@mysql5 ~]# rpm -qa mariadb*mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@template tools]# rpm-e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@template tools]# rpm-qa | grep mariadb
系统环境:
[root@mysql5 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@mysql5 ~]# uname -r
3.10.0-327.el7.x86_64
二、编译安装mysql
#安装依赖包
yum install libaio-devel ncurses-devel cmake gcc gcc-c++ bison -y
#文件目录创建
mkdir -p /home/nulige/mysql/3306/data
mkdir-p /home/nulige/mysql/3306/tmp
mkdir-p /home/nulige/mysql/3306/log
#创建用户组和mysql用户
groupadd mysql
useradd-s /sbin/nologin -g mysql -M mysql
id mysql
#创建软件目录
mkdir -p /home/nulige/mysql
cd/home/nulige/mysql
#下载软件
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget https://osdn.net/frs/g_redir.php?m=netix&f=%2Flonenmp%2Flnmpfiles%2Fmysql%2Fmysql-5.7.11.tar.gz
# utf8mb4格式解释
MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode。好在utf8mb4是utf8的超集,
除了将编码改为utf8mb4外不需要做其他转换。当然,为了节省空间,一般情况下使用utf8也就够了。
至于什么时候用,看你的做什么项目了。
在做移动应用时,会遇到ios用户会在文本的区域输入emoji表情,如果不做一定处理,就会导致插入数据库异常。
#解压安装
tar xzf boost_1_59_0.tar.gz
tar xzf mysql-5.7.11.tar.gz
cd mysql-5.7.11cmake-DCMAKE_INSTALL_PREFIX=/home/nulige/mysql/3306\-DMYSQL_DATADIR=/home/nulige/mysql/3306/data \-DWITH_BOOST=/home/nulige/mysql/boost_1_59_0 \-DSYSCONFDIR=/home/nulige/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/nulige/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/nulige/mysql/3306datadir= /home/nulige/mysql/3306/data
tmpdir= /home/nulige/mysql/3306/tmp
pid-file = /home/nulige/mysql/3306/data/my.pid
port= 3306default_storage_engine=InnoDB
innodb_autoinc_lock_mode= 2explicit_defaults_for_timestamp= truecharacter-set-client-handshake =FALSE
character_set_server=utf8
skip-name-resolve
max_connect_errors= 1000000max_allowed_packet=1G
connect_timeout= 3600wait_timeout= 3600interactive_timeout= 3600innodb_lock_wait_timeout= 10slave-skip-errors = 1032,1062log-error = /home/nulige/mysql/3306/log/error.log
slow_query_log=on
slow_query_log_file= /home/nulige/mysql/3306/log/slow-query-log.log
long_query_time= 1log-queries-not-using-indexes
log-slow-admin-statements
log-slow-slave-statements
server-id = 100log-bin = log-bin
binlog-format = ROW
#初始化数据库
chown -R mysql:mysql /home/nulige/mysql/3306/cd/home/nulige/mysql/3306/bin
./mysql_install_db --user=mysql --basedir=/home/nulige/mysql/3306 --datadir=/home/nulige/mysql/3306/data
备注:这里会报一个警告,直接忽略2017-05-19 16:33:16 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
意思:
之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃"--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码,--datadir目标目录下不能有数据文件。
#启动 数据库
service mysqld start
#设置开机自启动
[root@mysql5 ~]# systemctl enable mysqld.service
mysqld.serviceis not a native service, redirecting to /sbin/chkconfig.
Executing/sbin/chkconfig mysqld on
#查看端口
[root@mysql5 bin]# ss -lntup|grep 3306tcp LISTEN0 80 :::3306 :::* users:(("mysqld",pid=25042,fd=23))
#配置环境变量
echo 'PATH=/home/nulige/mysql/3306/bin/:$PATH' >>/etc/profile
source/etc/profile
echo $PATH
#查看mysql默认密码
[root@mysql5 bin]# cat /root/.mysql_secret
# Passwordset for user 'root@localhost' at 2017-05-19 16:33:16:AyjdUl!3-;*
#用默认密码,登录数据库
mysql -uroot -p':AyjdUl!3-;*' #这边密码要加引号,要么然的话存在转义问题
#修改密码(这个密码一定要足够复杂,不然会不让你改,提示密码不合法)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1qaz@WSX');
mysql>flush privileges;
mysql>exit
Bye
#登录数据库
[root@mysql5 bin]# mysql -uroot -p'1qaz@WSX'
8、查看mysql版本
[root@mysql5 bin]# mysql -V
mysql Ver14.14 Distrib 5.7.11, for Linux (x86_64) using EditLine wrapper
9、查看数据库用户表
mysql> select host,user frommysql.user;+-----------+-----------+
| host | user |
+-----------+-----------+
| localhost | mysql.sys |
| localhost | root |
+-----------+-----------+
2 rows in set (0.00 sec)