centos7-安装mysql5.6.36
本地安装了mysql5.7, 但和springboot整合jpa时会出现 hibernateException, 不知道为什么, 换个mysql5.6版本的mysql, 源码安装, cmake一直过不去, 后来改成rpm安装
1, 获取mysql5.6
ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.6/
下载:
其中 el6标识 centos 6, el7 标识centos 7
2, 安装
rpm -ivh MySQL-*
3, 启动
systemctl start mysql
4, 查看初始密码
cat /root/.mysql_secret
5, 更改密码
mysql -uroot -pKAKt5JmEjm6B8omVSET PASSWORD = PASSWORD(
'root'
);
6, 远程登陆设置
mysql> user mysql; mysql> select host, user, password from user; mysql> update user set password=password('root') where user='root'; mysql> update user set host='%' where user='root' and host='localhost';
授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里是你的密码' WITH GRANT option;
7, 设置开机启动
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
8, MySQL的默认安装位置
/var/lib/mysql/ #数据库目录 /usr/share/mysql #配置文件目录 /usr/bin #相关命令目录 /etc/init.d/mysql #启动脚本
9, 修改默认字符集等
vim /etc/my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[client] password = root port = 3306 default -character- set =utf8 [mysqld] port = 3306 character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci #(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写) lower_case_table_names=1 #(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; ) max_connections=1000 [mysql] default -character- set = utf8 |
10, 查看字符集
show variables like '%collation%'; show variables like '%char%';
源码安装:
1, 下载依赖
yum install gcc-c++
yum -y install ncurses-devel
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz tar -zxv -f /root/cmake-2.8.4.tar.gz cd cmake-2.8.4 ./configure
make && make install
2, 创建mysql 用户和用户组, 创建目录
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
mkdir -p /app/mysql-5.5.32/data
mkdir -p /app/mysql-5.5.32/tmp
3. 获取mysql
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
解压, 并编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.5.32 \ #安装路径
-DMYSQL_DATADIR=/app/mysql-5.5.32/data \ #数据文件路径
-DMYSQL_UNIX_ADDR=/app/mysql-5.5.32/tmp/mysql.sock \ #sock路径
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \ #默认的字符集
-DDEFAULT_COLLATION=utf8_general_ci \ #默认的校对规则
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ #额外支持的字符集
-DENABLED_LOCAL_INFILE=ON \ #打开LOCAL_INFILE功能
#开启支持多种引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITHREADLINE=1 \
-DWITHEMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make && make install
5, 复制参数文件
cp /app/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
6, 配置环境变量
echo 'export PATH=/app/mysql-5.5.32/bin:$PATH' >> /etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
7, 更改用户组权限
chown -R mysql.mysql /app/mysql-5.5.32
8, 执行数据库初始化脚本
./mysql_install_db --basedir=/app/mysql-5.5.32 --datadir=/app/mysql-5.5.32/data --user=mysql
9, 将mysql 加入系统启动
cp /app/mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
10, 启动
/etc/init.d/mysqld start
netstat -lntup | grep 3306
11, 设置用户, 赋予权限等
异常:
1, CMake Error: The source directory "/root/mysql-5.5.29-linux2.6-x86_64" does not appear to contain CM
下载的包不是源码包
2, 清空cmake, 重新编译
# make clean # rm -f CMakeCache.txt # rm -rf /etc/my.cnf
配置mysq忽略大小写:
vi /etc/my.cnf中加入lower_case_table_names = 1