部署环境
操作系统:CentOS-6.6-x86_64-bin-DVD1.iso
MySQL 版本:mysql-5.6.22.tar.gz
操作用户:root
系统 IP:192.168.1.205
主机名:edu-mysql-01
一、服务器配置:
1、配置网络
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" BOOTPROTO="static" HWADDR="00:0c:29:31:09:cf" IPV6INIT="yes" NM_CONTROLLED="yes" ONBOOT="yes" IPADDR=192.168.1.205 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
2、设置主机名
# vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=edu-mysql-01
3、设置IP 与主机名的映射
# vi /etc/hosts 127.0.0.1 edu-mysql-01 192.168.1.205 edu-mysql-01
4、两台数据库服务器的的selinux 都要disable
(永久关闭 selinux,请修改/etc/selinux/config,将 SELINUX改为 disabled)
# vi /etc/selinux/configSELINUX=disabled
5、重启操作系统
# reboot
二、源码安装 MySQL5.6.26:
1、使用下面的命令检查是否安装有MySQL Server:
# rpm -qa | grep mysql mysql-libs-5.1.73-3.el6_5.x86_64
如果是 CentOS7以上,请使用以下命令查看:
# rpm -qa | grep mariadb mariadb-libs-5.5.41-2.el7_0.x86_64
(因为没有 MySQL服务,因此没必要卸载。mysql-libs是MySQL的必要包)
(如果有的话可通过下面的命令来卸载掉,rpm -e mysql //普通删除模式或yum remove mysql mysql-*)
2、改防火墙设置,打开3306端口:
# vi /etc/sysconfig/iptables
增加如下行:
## MySQL -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
重启防火墙:
# service iptables restart
3、新增mysql用户组:
# groupadd mysql
4、新增mysql用户,并添加到mysql用户组:
# useradd -r -g mysql mysql
5、新建MySQL执行文件目录(后面会把编译好的mysql程序安装到这个目录):
# mkdir -p /usr/local/mysql
(-p参数的作用是:如果最终目录的父目录不存在也会一并创建)
6、新建MySQL数据库数据文件目录:
#mkdir -p /home/mysql/data #mkdir -p /home/mysql/logs #mkdir -p /home/mysql/temp
(注意:上面的logs及temp目录是为了以后将MySQL的数据文件与执行程序文件分离,如果你打算设置到不同的路径,注意修改对应的执行命令和数据库初始化脚本。正式生产环境,建议数据目录和日志目录都使用单独的分区来挂载,不同分区属于不同的磁盘或磁盘组。)
# vi /etc/profile
##在profile文件末尾增加两行
# mysql env param
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
使 PATH搜索路径立即生效:
# source /etc/profile
8、安装编译MySQL需要的依赖包:
(mysql 从5.5 版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档
dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html,安装基本依赖包,先用yum安装 cmake、automake、autoconf,另MySQL 5.5.x需要最少安装的包有:bison,gcc、gcc-c++、ncurses-devel):
#yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-develautoconf automake
9、进入/usr/local/src 目录,上传mysql-5.6.22.tar.gz 源代码到/usr/local/src 目录:
# cd /usr/local/src
10、开始编译安装mysql-5.2.22:
解压缩源码包:
#tar -zxvf mysql-5.6.22.tar.gz
进入解压缩源码目录:
使用 cmake源码安装mysql(如果你打算安装到不同的路径,注意修改下面语句中/usr/local/mysql和/home/mysql/data路径!)
#cd mysql-5.6.22
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
配置解释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 设置安装目录 -DMYSQL_DATADIR=/home/mysql/data 设置数据库存放目录 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock设置UNIX socket 目录 -DMYSQL_USER=mysql 设置运行用户 -DDEFAULT_CHARSET=utf8 设置默认字符集,默认latin1 -DEFAULT_COLLATION=utf8_general_ci 设置默认校对规则,默认latin1_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 添加InnoDB 引擎支持 -DENABLE_DOWNLOADS=1 自动下载可选文件,比如自动下载谷歌的测试包 -DMYSQL_TCP_PORT=3306 设置服务器监听端口,默认3306 -DSYSCONFDIR=/etc 设置my.cnf 所在目录,默认为安装目录)
执行过程中会出现:
CMake Error: Problem with tar_extract_all(): Invalid argument CMake Error: Problem extracting tar: /usr/local/src/mysql-5.6.26/source_downloads/gmoc k-1.6.0.zip
解决方法:(我这里没有加-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock)
cd mysql 目录下面会发现有一个source_downloads 目录,需要解压unzip gmock-1.6.0.zip,然后再重新执行上述配置过程。当然你也可以去掉-DENABLE_DOWNLOADS=1这个选项,不编译谷歌的测试包也没有什么问题,但是之前的某些版本会出现无法编译的问题.
11、cmake结束后开始编译源码,这一步时间会较长,请耐心等待:
# make
12、安装编译好的程序:
# make install
(注意:如果需要重装mysql,在/usr/local/src/mysql-5.6.22在执行下make install就可以了,不需要再cmake和make)
13、清除安装临时文件:
# make clean
14、修改mysql目录拥有者为mysql用户:
#chown -Rf mysql:mysql /usr/local/mysql
#chown -Rf mysql:mysql /home/mysql
15、进入mysql执行程序的安装路径:
# cd /usr/local/mysql
16、执行初始化配置脚本,创建系统自带的数据库和表(注意:路径/home/mysql/data需要换成你自定定义的数据库存放路径):
[root@edu-mysql-01 mysql-5.6.22]# cd /usr/local/mysql [root@edu-mysql-01 mysql]# pwd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
17、初始化脚 本在/usr/local/mysql下生成了配置文件my.cnf,需要更改该配置文件的所有者:
#ls -lah
18、注意:
(1)Tips:在启动Mysql服务时,会按照一定次次序搜索my.cnf,先在/etc目录下找。,找不到则会搜索mysql程序目录 下是否有my.cnf
(2)需要注意CentOS 6版操作系统的最小安装完成后,即使没有安装mysql,在/etc/目录 下也会存在一个my.cnf文件,建议将此文件 更名为其他的名字,否则该文件会干扰源码安装的MySQL的正确配置,造成无法启动,修改/etc/my.cnf操作如下:
可以mv /etc/my/cnf /etc/my.cnf.bak
也可以:删除掉/etc/my.cnf这个文件 :rm -rf /etc/my.cnf
如果你需要用于生产环境,不需要急着做下面的mysql启动操作,建议把上一步骤中mysql初始化生成的/usr/local/mysql/my.cnf删除,然后把你优化好的mysql配置文件my.cnf放到/etc/下(这是做mysql复制和mysql优化的经验)
我这里使用的/etc/my.cnf
19.编辑/etc/my.cnf
#vi /etc/my.cnf
[client] port=3306 #socket=/usr/local/mysql/mysql.sock socket=/tmp/mysql.sock [mysqld] character-set-server=utf8 collation-server=utf8_general_ci skip-external-locking skip-name-resolve user=mysql port=3306 basedir=/usr/local/mysql datadir=/home/mysql/data #server_id=... #socket=/usr/local/mysql/mysql.sock socket=/tmp/mysql.sock log-error=/home/mysql/logs/mysql_error.log pid-file=/home/mysql/mysql.pid open_files_limit=10240 back_log=600 max_connections=500 max_connect_errors=6000 wait_timeout=605800 #open_tables=6000 #table_cache=650 #opened_talbes=630 max_allowed_packet=32M sort_buffer_size=4M join_buffer_size=4M thread_cache_size=300 query_cache_type=1 query_cache_size=256 query_cache_limit=2M query_cache_min_res_unit=16K tmp_table_size=256M max_heap_table_size=256M key_buffer_size=256M read_buffer_size=1M read_rnd_buffer_size=16M bulk_insert_buffer_size=64M lower_case_table_names=1 default-storage-engine=INNODB innodb_buffer_pool_size=512 innodb_log_buffer_size=32M innodb_log_file_size=128M innodb_flush_method=O_DIRECT ########################## thread_concurrency=32 long_query_time=2 slow-query-log=on slow-query-log-file=/home/mysql/logs/mysql-slow.log [mysqldump] quick max_allowed_packet=32M [mysql_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
其中innodb_buffer_pool_size的大小为分配内存的三分之一到二分之一
20.复制服务启动脚本:
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
21.启动mysql服务
service mysql start
# service mysql start Starting MySQL. SUCCESS!
22.设置MySQL开机自动启动服务:
#chkconfig mysql on
设置mysql数据库root用户的本地登录密码(初始用户没有密码):
#mysqladmin -u root password 'root'
23.登录并修改MySQL用户root的密码
# mysql -u root -pEnter password: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) 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 changed mysql> update user set password=password('root') where user='root'; Query OK, 4 rows affected (0.06 sec)Rows matched: 5 Changed: 4 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
允许root远程登录,设置远程登录密码:123456
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
注意:真实生产环境,应用操作不要使用root用户操作
24.运行安全设置脚本,强烈建议生产服务器使用(可选)
[root@edu-mysql-01~]# /usr/local/mysql/bin/mysql_secure_installation
以上就是MySQL,分布式,CentOS的内容,更多相关内容请关注PHP中文网(www.php.cn)!

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

The relationship between SQL and MySQL is the relationship between standard languages and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor