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-*
如果缺少依赖, 可以挂载centos的本地yum源解决 (https://www.cnblogs.com/wenbronk/p/9357471.html)
如果提示冲突, 使用 rpm -e xxx --nodes 卸载就可以
3, 启动, 通过netstat -nltp 查看端口监听( 老版本是 mysqld 服务)
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;
必须刷新
flush privileges;
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
[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.38.tar.gz
解压, 并编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.6.38 \ #安装路径
-DMYSQL_DATADIR=/app/mysql-5.6.38/data \ #数据文件路径
-DMYSQL_UNIX_ADDR=/app/mysql-5.6.38/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
# 注意去掉所有注释, 并无bom格式
5, 复制参数文件
cp /app/mysql-5.6.38/support-files/my-small.cnf /etc/my.cnf
6, 配置环境变量
echo 'export PATH=/app/mysql-5.6.38/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, 设置用户, 赋予权限等
3, 创建新用户并授权
https://www.cnblogs.com/sos-blue/p/6852945.html
https://www.cnblogs.com/xujishou/p/6306765.html
异常:
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
mysql 5.7 的安装:
1), 需要安装的包
2), 修改用户名添加权限等
https://www.cnblogs.com/daemon-/p/9009360.html
a, 修改不需要密码登陆, 修改/etc/my.cnf
[mysqld] datadir=/usr/local/mysql/data basedir=/usr/local/mysql socket=/tmp/mysql.sock user=mysql port=3306 character-set-server=utf8 # 取消密码验证 skip-grant-tables # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # skip-grant-tables [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
b, 登陆mysql
mysql -u root -p
直接回车就可登陆
c, 修改密码
>>update user set authentication_string=password('你的密码') where user='root'; >>flush privileges; >>exit;
d, 将/etc/my.cnf中的skip-grant-tables删除
e, 登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)
如果报错:
https://www.cnblogs.com/ivictor/p/5142809.html
/usr/local/mysql/bin/mysql -u root -p >>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码'; >>exit;
f, 加入开机启动
# 将mysql加入服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 开机自启
chkconfig mysql on
# 开启
service mysql start