Linux(CentOS7)安装MySQL-5.7版本
1. 从官网下载mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 官网:http://dev.mysql.com/downloads/mysql/
# wget -chttp://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
2. 创建mysql的用户组/用户, data目录及其用户目录
# groupadd mysql
# useradd -r -g mysql mysql
# mkdir -p /data/mysqldb
3. 解压安装包并将解压包里的内容拷贝到mysql的安装目录/home/mysql
# tar -xzvf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
# cd mysql-5.7.14-linux-glibc2.5-x86_64
# mv * /usr/local/mysql
# mkdir -p /usr/local/mysql 创建mysql安装目录,可以把解压的mysql-5.7.14-linux-glibc2.5-x86_64文件夹下的文件移到目录下
4. 初始化mysql数据库cd /usr/local/mysql
\# ./bin/mysql\_install\_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb
2015-11-1002:09:17 \[WARNING\] mysql\_install\_db is deprecated. Please consider switching to mysqld --initialize
2015-11-1002:09:23 \[WARNING\] The bootstrap logisn't empty:
2015-11-1002:09:23 \[WARNING\] 2015-11-10T10:09:18.114182Z 0 \[Warning\] --bootstrap is deprecated. Please consider using --initialize instead
2015-11-10T10:09:18.129343Z 0 \[Warning\] Changed limits: max\_open\_files: 1024 (requested 5000)
2015-11-10T10:09:18.129408Z 0 \[Warning\] Changed limits: table\_open\_cache: 431 (requested 2000)
p.s. : mysql5.7新特性:由上面可以看出,mysql_install_db 已经不再推荐使用了,建议改成mysqld --initialize 完成实例初始化。
\# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize改用 mysqld --initialize 后,如果 datadir 指向的目标目录下已经有数据文件, 会出现如下提示:\# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize2016-04-08T01:46:53.153530Z 0 \[Warning\] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit\_defaults\_for\_timestamp server option (see documentation for more details).2016-04-08T01:46:53.155856Z 0 \[ERROR\] --initialize specified but the data directory has files in it. Aborting.2016-04-08T01:46:53.155879Z 0 \[ERROR\] Aborting由上可知, 我们需要清空mysql的data目录, 执行清空命令如下:\# cd /data/mysqldb# rm -fr \*
然后重新执行初始化命令如下:
[root@localhost /] cd /usr/local/mysql
[root@localhost mysql ] ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize
[root@localhostmysql ]2016-04-08T01:47:57.556677Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-04-08T01:47:59.945537Z 0 [Warning] InnoDB: New logfiles created, LSN=45790
2016-04-08T01:48:00.333528Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-04-08T01:48:00.434908Z 0 [Warning] No existing UUID has been found, so we assume that this is thefirsttime that this server has been started. Generating anew UUID: ece26421-fd2b-11e5-a1e3-00163e001e5c.2016-04-08T01:48:00.440125Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2016-04-08T01:48:00.440904Z 1 [Note] A temporary password is generated for root@localhost: **mjT,#x_5sW
牢记上面的随机密码, 如上**mjT,#x_5sW, 下面我们修改密码时需要用到。
5. 检测下是否能启动mysql服务
# cd /usr/local/mysql# ./support-files/mysql.server start
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). #没有经过cmake编辑过的,初始化数据库会失败;
解决办法:vim support-files/mysql.server 指定datadir=/data/mysqldb basedir=/usr/local/mysql
Starting MySQL… SUCCESS!
若改用了/usr/local/mysql为mysql的安装目录basedir, 则在启动服务时会出现如下错误:
[root@localhost mysql] #./support-files/mysql.server start
[root@localhostmysql ]./support-files/mysql.server: line 276: cd: /usr/local/mysql: No such fileor directory
[root@localhostmysql ] Starting MySQL ERROR! Couldn’t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
由上面可知mysql的tar.gz安装包的默认安装目录为/usr/local/mysql, 这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径, 如下:
- [root@localhostmysql ]
- # vim support-files/mysql.server
- --------------------------
- …
- basedir=/usr/local/mysql
- datadir=/data/mysqldb
- …
- --------------------------
- # ./support-files/mysql.server start
- Starting MySQL… SUCCESS!
6. 创建软链接
\# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
7. 创建配置文件
将默认生成的my.cnf备份
\# mv /etc/my.cnf /etc/my.cnf.bak
进入mysql的安装目录支持文件目录
\# cd /usr/local/mysql/support-files
拷贝配置文件模板为新的mysql配置文件,
\# cp my-default.cnf /etc/my.cnf
可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行.
如下是我修改配置文件/etc/my.cnf, 设置编码为utf8以防乱码
\# vim /etc/my.cnf\[mysqld\]basedir = /usr/local/mysqldatadir = /data/mysqldbcharacter\_set\_server=utf8init\_connect='SET NAMES utf8'\[client\]default-character-set=utf8
8. 配置mysql服务开机自动启动
拷贝启动文件到/etc/init.d/下并重命令为mysqld
\# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
增加执行权限
\# chmod 755 /etc/init.d/mysqld
检查自启动项列表中没有mysqld这个,如果没有就添加mysqld:
\# chkconfig --list mysqld# chkconfig --add mysqld
设置MySQL在345等级自动启动
\# chkconfig --level 345 mysqld on
或用这个命令设置开机启动:
\# chkconfig mysqld on
9. mysql服务的启动/重启/停止
启动mysql服务
\# service mysqld start
重启mysql服务
\# service mysqld restart
停止mysql服务
\# service mysqld stop
可以先将文件最底部这句删除或注释掉:sql\_mode=NO\_ENGINE\_SUBSTITUTION,STRICT\_TRANS\_TABLES
10. 初始化mysql用户root的密码
先将mysql服务停止
\# service mysqld stop
进入mysql安装目录, 执行:
# cd /usr/local/mysql
# ./bin/mysqld_safe --skip-grant-tables --skip-networking&
[1] 6225
[root@localhost mysql]# 151110 02:46:08 mysqld_safe Logging to ‘/data/mysqldb/localhost.localdomain.err’.151110 02:46:08 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb
另外打开一个终端(p.s. 如果是ssh连接登录的, 另外创建一个ssh连接即可), 执行操作如下:
# mysql -u root mysql#运行此句时,需要先执行上一句:./bin/mysqld_safe
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A********************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use mysql;Database changed
mysql> UPDATE user SET password=PASSWORD(‘root’) WHERE user=‘root’;ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
mysql> update user set authentication_string = PASSWORD(‘root’) where user = ‘root’;
Query OK, 1 row affected, 1 warning (0.02 sec)Rows matched: 1 Changed: 1 Warnings: 1
#MySQL5.7新特性,Users表中没有password字段了,authentication_string 就是password
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \s--------------mysql Ver 14.14 Distrib 5.7.9, for linux-glibc2.5 (x86_64) using EditLine wrapperConnection id: 2Current database: mysqlCurrent user: root@SSL: Not in useCurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 5.7.9 MySQL Community Server (GPL)Protocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8Db characterset: utf8Client characterset: utf8Conn. characterset: utf8UNIX socket: /tmp/mysql.sockUptime: 4 min 47 secThreads: 1 Questions: 43 Slow queries: 0 Opens: 127 Flush tables: 1 Open tables: 122 Queries per second avg: 0.149--------------
mysql> exit;Bye
到此, 设置完mysql用户root的密码且确保mysql编码集是utf8, 注意上面,新版本的mysql.user表里的密码字段是authentication\_string
快捷键ctrl + c停止# ./bin/mysqld\_safe ...命令, 重新启动mysql服务, 用新密码连接mysql:
# service mysqld startStarting MySQL SUCCESS!
[root@localhost bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.9************************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql > exit;Bye
咦?又要我改密码, 我们通过mysqladmin来修改密码, 先输入原密码是上面步骤修改的新密码root, 再设置新密码!!!
# cd /usr/local/mysql
# ./bin/mysqladmin -u root -p password
#这个password是参数,不是要设置成root密码的值Enter password: New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.9 MySQL Community Server (GPL)Copyright © 2000, 2015, Oracle and/or its affiliates. All rights reserved.******************************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql>
或直接:
# ./bin/mysqladmin -uroot -p’g!#l4:6+rMnT’ password ‘root’
mysqladmin: [Warning] Using a password on the command line interface can be insecure.Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
其中,g!#l4:6+rMnT就是我们在使用mysqld --initialize时牢记下的随机密码
11. mysql远程授权
格式如下:
mysql> grant all \[privileges\] on db\_name.table\_name to 'username'@'host' identified by 'yourpassword';
示例如下:
mysql> `grant` all privileges on \*.\* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
或用
mysql> grant all on \*.\* to 'root'@'%' identified by 'root';
到此, 完成了mysql的安装 及配置!!!
注:最后windows远程访问linux-mysql连接失败,没有开放端口3306:解决:iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
已验证安装MySQL5.7不需要cmake.
Linux(CentOS7)安装MySQL-5.7版本相关推荐
- Linux CentOS7安装MySQL(yum方式)
记录第一次安装 MySQL . 1)先检查系统是否安装 MySQL . yum list installed mysql* rpm -qa | grep mysql* 2)查看有没有 MySQL 安 ...
- linux/CentOS7安装MySQL(完整版)【笔记自用】
在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1. 先检查系统是否安装有mysql [ro ...
- centos7安装mysql日志空白_centos7安装Mysql爬坑记录 - G
centos7安装Mysql爬坑记录 查看是否已安装 使用下列命令查看是否已经安装过mysql/mariadb/PostgreSQL 如果未安装,不返回任何结果(ECS的centos镜像默认未安装任何 ...
- CentOS7安装mysql数据库完整过程以及安装中遇到的各种问题的解决方案
1.首先下载mysql安装包 可以从官网下载:http://dev.mysql.com/downloads/mysql/(可以直接浏览器百度mysql官网的安装包,按照自己的需要选择相应的mysql版 ...
- 在Linux上安装Mysql 以及 涉及问题
在Linux上安装Mysql 一:准备工作 1.检查当前系统是否安装过Mysql (1)CentOS6 的环境下 命令:rpm -qa|grep mysql 默认在Linux在安装的时候,自带了mys ...
- 生产环境centos7 安装mysql 5.7.35
生产环境centos7 安装mysql 5.7.35 1.初始化系统,并重启 2.卸载原有mysql 2.安装依赖 4.创建mysql的用户 5.创建mysql的数据目录 6.安装 mysql 7. ...
- linux下安装mysql数据库[yum install版]
原文链接:linux下安装mysql数据库[yum install版] 在CentOS7中默认安装有MariaDB,这个是MySQL的分支,yum直接覆原有MariaDB, 或安装包报错无法解决依赖问 ...
- Linux编译安装qt5.9,Linux CentOS7 安装 Qt 5.9.2
Linux CentOS7 安装 Qt 5.9.2 参考链接 http://doc.qt.io/qt-5/linux.html sudo yum groupinstall "C Develo ...
- linux mysql授权外部访问权限,Linux中安装Mysql授权远程访问
Linux中安装MySQL 因为使用yum安装.安装过程需保证网络通畅 一.安装mysql 1.yum安装mysqlCentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql, ...
- centos7 安装mysql php,Centos7安装mysql与php的方法
本文主要和大家分享Centos7安装mysql与php的方法,希望能帮助到大家. 相关mysql视频教程推荐:<mysql教程> 官网下载安装mysql-server 依次使用下面三个命令 ...
最新文章
- 深入理解 Embedding层的本质
- php final这个关键词代表什么,php面向对象之final关键字用法及实例
- DataGridView中回车键的妙用
- 改进 网站资源探测工具(添加代理)
- React Native实现NbaApp
- BF533和触摸屏接口芯片TSC2200调试日志
- php json -gt;访问,【转】Php+ajax+jsonp解决ajax跨域问题
- leetcode876 链表中间的结点
- wireshark找不到接口_下水管漏水,维修师傅看一眼就收了200,自己换其实不到10块...
- [转载] Java中final关键字
- @SuppressLint(HandlerLeak),或Handler使用有警告;
- 书------编程书(FoxPro)
- 微信文件夹的dat文件怎么打开_微信文件夹里的照片文件是DAT格式怎么才能打开?...
- Android--手机一键Root原理分析
- 多文件自平衡云传输(四)资源发送端 —————— 开开开山怪
- python将后宫佳丽三千做成照片墙
- 音准听力测试软件app,听音练耳app神器考试用
- VirtualBox报错:不能为虚拟电脑XXX打开一个新任务
- 神经网络训练怎么看收敛,神经网络收敛的定义是
- 人力资源管理计算机基础,人力资源管理-专-李佑强-计算机应用基础实践报告.doc...