2017-12-26--mysql(5.6.15),linux下安装使用
本文档的目的是,指导使用者安装、配置、还原所需要用到的mysql数据库。仅提供linux版本服务器的安装说明,且linux版本为64位的Centos6.4。同时,会提供的mysql安装包(MySQL-5.6.15-1.linux_glibc2.5.x86_64.rpm-bundle.tar)和还原数据库所需用到的sql脚本。
mysql安装提供的tar包,解压到/opt/mysql(实际使用可变换目录)目录下。解压后,会出现如下几个rpm包,我们只用到其中红色字体的两个rpm包。
[root@localhost mysql]# tar -xvf MySQL-5.6.15-1.linux_glibc2.5.x86_64.rpm-bundle.tar
MySQL-devel-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.15-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.15-1.linux_glibc2.5.x86_64.rpm
安装步骤,如下说明:
一、检查环境,删除已有的旧版本
l 检查mysql,如已存在则需要删除。执行脚本如下
rpm -qa mysql
rpm -qa mysql-5.1.66-2.el6_3.x86_64
rpm -e mysql --nodeps;
l 检查mysql-server,如已存在则需要删除。执行脚本如下
rpm -qa mysql-server
mysql-server-5.1.66-2.el6_3.x86_64
rpm -e mysql-server --nodeps;
l 检查mysql- client,如已存在则需要删除。执行脚本如下
rpm -qa mysql-client
测试中发现没有安装,不用删除
l 检查mysql- libs,如已存在则需要删除。执行脚本如下
rpm -qa mysql-libs
mysql-libs-5.1.66-2.el6_3.x86_64
rpm -e mysql-libs --nodeps;
二、安装mysql服务器
安装mysql成功后,会为root随机生成一个密码,密码保存在'/root/.mysql_secret'文件内。
[root@localhost mysql]# rpm -ivh MySQL-server-5.6.15-1.linux_glibc2.5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
2016-05-12 15:37:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-05-12 15:37:48 22636 [Note] InnoDB: The InnoDB memory heap is disabled
2016-05-12 15:37:48 22636 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-05-12 15:37:48 22636 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-05-12 15:37:48 22636 [Note] InnoDB: Using Linux native AIO
2016-05-12 15:37:48 22636 [Note] InnoDB: Using CPU crc32 instructions
2016-05-12 15:37:48 22636 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-05-12 15:37:48 22636 [Note] InnoDB: Completed initialization of buffer pool
2016-05-12 15:37:48 22636 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-05-12 15:37:48 22636 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-05-12 15:37:48 22636 [Note] InnoDB: Database physically writes the file full: wait...
2016-05-12 15:37:48 22636 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-05-12 15:37:49 22636 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-05-12 15:37:50 22636 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-05-12 15:37:50 22636 [Warning] InnoDB: New log files created, LSN=45781
2016-05-12 15:37:50 22636 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-05-12 15:37:50 22636 [Note] InnoDB: Doublewrite buffer created
2016-05-12 15:37:50 22636 [Note] InnoDB: 128 rollback segment(s) are active.
2016-05-12 15:37:50 22636 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-05-12 15:37:50 22636 [Note] InnoDB: Foreign key constraint system tables created
2016-05-12 15:37:50 22636 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-05-12 15:37:50 22636 [Note] InnoDB: Tablespace and datafile system tables created.
2016-05-12 15:37:50 22636 [Note] InnoDB: Waiting for purge to start
2016-05-12 15:37:50 22636 [Note] InnoDB: 5.6.15 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2016-05-12 15:37:57 22636 [Note] Binlog end
2016-05-12 15:37:57 22636 [Note] InnoDB: FTS optimize thread exiting.
2016-05-12 15:37:57 22636 [Note] InnoDB: Starting shutdown...
2016-05-12 15:37:58 22636 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2016-05-12 15:37:58 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-05-12 15:37:58 22659 [Note] InnoDB: The InnoDB memory heap is disabled
2016-05-12 15:37:58 22659 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-05-12 15:37:58 22659 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-05-12 15:37:58 22659 [Note] InnoDB: Using Linux native AIO
2016-05-12 15:37:58 22659 [Note] InnoDB: Using CPU crc32 instructions
2016-05-12 15:37:58 22659 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-05-12 15:37:58 22659 [Note] InnoDB: Completed initialization of buffer pool
2016-05-12 15:37:58 22659 [Note] InnoDB: Highest supported file format is Barracuda.
2016-05-12 15:37:58 22659 [Note] InnoDB: 128 rollback segment(s) are active.
2016-05-12 15:37:59 22659 [Note] InnoDB: Waiting for purge to start
2016-05-12 15:37:59 22659 [Note] InnoDB: 5.6.15 started; log sequence number 1625977
2016-05-12 15:37:59 22659 [Note] Binlog end
2016-05-12 15:37:59 22659 [Note] InnoDB: FTS optimize thread exiting.
2016-05-12 15:37:59 22659 [Note] InnoDB: Starting shutdown...
2016-05-12 15:38:01 22659 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
[root@localhost mysql]#
三、安装mysql客户端
[root@localhost mysql]# rpm -ivh MySQL-client-5.6.15-1.linux_glibc2.5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
四、启动mysqld服务
查找mysql.server
[root@localhost /]# find / -name mysql.server
/usr/share/mysql/mysql.server
拷贝mysql.server到/etc/rc.d/init.d/mysqld
[root@terminal opt]# cp /usr/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
添加mysqld执行权限
[root@terminal opt]#chmod +x /etc/rc.d/init.d/mysqld
添加mysqld到系统服务
[root@terminal opt]#chkconfig --add mysqld
检查mysqld是否生效
[root@terminal opt]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
五、启动mysql和mysqld
[root@localhost mysql]# service mysql start
Starting MySQL. [确定]
[root@terminal opt]# service mysqld start
Starting MySQL. [确定]
六、关闭或重启mysql和mysqld
mysql
[root@localhost ~]# service mysql restart
Shutting down MySQL.. [确定]
Starting MySQL. [确定]
[root@localhost ~]# service mysql stop
Mysqld服务
[root@terminal opt]# service mysqld restart
Shutting down MySQL.. [确定]
Starting MySQL. [确定]
[root@terminal opt]# service mysqld stop
七、修改root密码、设置权限
使用客户端连接mysql并修改root密码,必须修改密码,否则无法使用。
安装mysql5.6成功后,会为root随机生成一个密码,我们首次使用root登陆时需要,需要使用这个密码,然后修改root密码。操作命令可以参考下文红色字体。
[root@localhost mysql]# cat /root/.mysql_secret
# The random password set for the root user at Thu May 12 15:37:53 2016 (local time): nghlklAC
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.15
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set password=password('root');
Query OK, 0 rows affected (0.00 sec)
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
设置权限。必须设置权限,否则mysql不允许本机外的其他客户端连接。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
附录A、关闭SELinux权限的操作
设置权限。必须设置权限,否则mysql不允许本机外的其他客户端连接。
查看SELinux权限,如果是Enforcing则说明没有关闭权限。
[root@localhost mysql]#
Enforcing
修改/etc/selinux/config文件,将enforcing改为disabled
[root@localhost mysql]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
~
~
~
~
~
~
"/etc/selinux/config" 13L, 457C 已写入
修改这个配置文件后,需要重启linux服务器,才能生效。Disabled代表关闭了selinux。
Last login: Thu May 12 15:17:19 2016 from 192.168.2.130
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# getenforce
Disabled
附录B、还原mysql数据库
利用sql备份脚本
还原前,需要先创建数据库,这样做的目的是可以灵活定义数据库名称。
使用mysql客户端,登录到mysql(mysql -u root -p)。利用create命令创建需要的数据库(例如create database db_name character set =utf8;),利用use命令将当前数据库切换到刚刚创建的数据库上(例如use db_name;),然后利用source命令还原数据库(例如source /opt/xxx/20160513.sql)。其中,db_name为你需要用到的数据库名称。
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 259
Server version: 5.6.15 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database httc character set =utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create database db_name character set =utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use db_name;
Database changed
mysql> source /opt/xxx/20160513.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.46 sec)
Query OK, 0 rows affected (0.00 sec)
。。。。。。
mysql>
附录C、设置mysql不区分数据库表名大小写
查找my.cnf文件,然后在最后一行添加lower_case_table_names = 1,之后重启mysql。
[root@localhost ~]# find / -name my.cnf
/usr/my.cnf
[root@localhost ~]# vim /usr/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names = 1
重启后,在mysql客户端执行查询语句,出现如下结果则代表设置mysql不区分表名大小写成功。
mysql> show variables like "%case%" ;
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
2 rows in set (0.00 sec)
mysql>
2017-12-26--mysql(5.6.15),linux下安装使用的更多相关文章
- Nginx 在 Linux 下安装与搭建集群
		
搭建集群图例 集群搭建图如下,为了简单一点,使用一个Nginx服务器+两个Tomcat服务器,省略数据库部分: 环境说明 Linux 为 CentOS 7.2 发行版 + Java jdk 1.8 + ...
 - linux下安装mysql(rpm文件安装)
		
数据库包下载: https://www.mysql.com/downloads/ 在GPL开原协议的社区开源版里边下载 我们用mysql community server里边的 其中workbench ...
 - Linux下安装mysql教程
		
Linux下安装mysql MySQL官网:https://dev.mysql.com/downloads/mysql/ 到mysql官网下载mysql编译好的二进制安装包,在下载页面Select ...
 - (转载)Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记
		
Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记 Linux下配LMAP环境,花了我好几天的时间.之前没有配置过,网上的安装资料比较混乱,加上我用的版本问题,安装过程 ...
 - Linux下安装JDK,Tomcat,Mysql详细教程
		
1. 概述 今天教大家在linux下安装jdk,mysql以及tomcat.在javaweb开发中,最后完成的项目代码,一般都是布在linux服务器下的.因为linux服务器可以说是安全性稳定性都比w ...
 - linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql.
		
linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql. 2013-03-04 1 ...
 - Linux下安装mysql(2) 及常见问题解决(CentOS)
		
上一篇讲了基本的安装,这篇姑且算作进阶吧 链接Linux下安装mysql(1) 1.准备好mysql的rpm安装包 2.解压并进入usr/local/mysql 3.先执行useradd mysql( ...
 - MySQL入门——在Linux下安装和卸载MySQL
		
MySQL入门——在Linux下安装和卸载MySQL 摘要:本文主要学习了如何在Linux系统中安装和卸载MySQL数据库. 查看有没有安装过MySQL 使用命令查看有没有安装过: [root@loc ...
 - 在Linux下安装和使用MySQL
		
[简 介] 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有Windows下使用SQL Server的经验,觉得在Linu ...
 
随机推荐
- CodeForces #549 Div.2 D. The Beatles
			
题目 解题思路 关键是要 ,找出L 的组合,然后遍历L的组合,用最大公约数就可以算出来当前L的值要停多少次 怎么找出L的组合呢?饭店是每隔K 有一个,是重复的,我们只需要算出第一个饭店两侧,起点和停顿 ...
 - u-boot调试串口输出对应的系统函数
			
接上Debug串口,启动机器,u-boot哗啦啦地打印一行行的字符.刚接触u-boot的时候,对机器后台做了什么,几乎一无所知. 如果要很有信心地定制出一个简单并且可靠的系统,或者快速完成一项新的任务 ...
 - AWS deepracer
			
0.安装 坑很多,Ubuntu16.04上安python3,gazebo9,各种包,最后在python2下roslaunch,参见我爱豆的github: https://github.com/exit ...
 - Linux常用命令之-删除文件
			
在测试过程中,有时候会需要删除一些文件,例如日志文件过大等,这里汇总一些删除文件常用的命 已这个系统内的文件为例 删除文件(即这个文件被删除) 单个删除:rm -f + 文件名 eg:rm -f 2 ...
 - vs2017 在win10下安装后开始运行asp.net core 项目时出错
			
vs2017 在win10下安装后开始运行asp.net core 项目时出错 报找不到什么 解决方法: 下载 asp.net 2.2 安装好,重新启动电脑问题解决.
 - jQuery通过ajax请求php遍历json数组到table中的代码
			
html代码(test.html),js在html底部 具体代码如下所示: <!DOCTYPE html> <html lang="en"> <hea ...
 - Oracle数据库查询所有关键字
			
管理员账户登录后,执行以下命令: select * from v$reserved_words
 - MySQL SQL Explain输出学习
			
MySQL的explain命令语句提供了如何执行SQL语句的信息,解析SQL语句的执行计划并展示,explain支持select.delete.insert.replace和update等语句,也支持 ...
 - Python3.0科学计算学习之绘图(二)
			
(1) np.mashgrid()函数:-----生成网络点坐标矩阵,可以是二维网络矩阵,也可以是三维网络矩阵.其中,每个交叉点就是网络点,描述这些网络点的矩阵就是坐标矩阵(横坐标矩阵X中的每个元素与 ...
 - Pycharm中Python3连接Oracle
			
一.环境配置:系统:win7.10 (64位)软件:1.Python3.7.2 (64位)2.instantclient-basic-windows.x64-11.2.0.4.0.zip(64位) - ...