`
lxwt909
  • 浏览: 566040 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

CentOS安装MySQL(rpm方式)

阅读更多

       首先你需要下载MySQL安装包,下载地址如下:

       http://ftp.ntu.edu.tw/pub/MySQL/Downloads/

       这里我以MySQL5.6.26-1.el7版本为例,其中安装包里的x86_64表示是x86架构的64位CPU,其中必须下载的两个安装包为:

       MySQL-server-5.6.26-1.el7.x86_64.rpm
       MySQL-client-5.6.26-1.el7.x86_64.rpm

       其他安装包为可选的,当你需要该功能时,再单独补充安装.不过这里我建议你下载bundle.tar结尾的压缩包文件,因为里面已经包括了MySQL所有安装组件。

 

       下载完成后,可以通过rz命令将其上传至你的CentOS服务器,这里我以上传到CentOS的/opt目录下:

 上传完成后你需要使用tar命令解压刚刚上传的压缩包文件,执行命令如下:

tar -xvf MySQL-5.6.16-1.el6.x86_64.rpm-bundle.tar

 

 

首先你需要检查是否已经安装了MySQL:

rpm -qa | grep mysql

如果已经安装了MySQL,则通过如下命令进行卸载:

rpm -e --nodeps mysql   //卸载MySQL,或者用yum remove mysql命名卸载

然后你需要先安装MySQL-server,执行命令如下:

rpm -ivh MySQL-server-5.6.16-1.el6.x86_64.rpm

 安装过程如下:

[root@yida opt]# rpm -ivh MySQL-server-5.6.16-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2015-11-16 02:00:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-16 02:00:36 1156 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-11-16 02:00:36 1156 [Note] InnoDB: The InnoDB memory heap is disabled
2015-11-16 02:00:36 1156 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-11-16 02:00:36 1156 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-11-16 02:00:36 1156 [Note] InnoDB: Using Linux native AIO
2015-11-16 02:00:36 1156 [Note] InnoDB: Not using CPU crc32 instructions
2015-11-16 02:00:36 1156 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-11-16 02:00:36 1156 [Note] InnoDB: Completed initialization of buffer pool
2015-11-16 02:00:36 1156 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-11-16 02:00:36 1156 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-11-16 02:00:36 1156 [Note] InnoDB: Database physically writes the file full: wait...
2015-11-16 02:00:36 1156 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-11-16 02:00:37 1156 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-11-16 02:00:39 1156 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-11-16 02:00:39 1156 [Warning] InnoDB: New log files created, LSN=45781
2015-11-16 02:00:39 1156 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-11-16 02:00:39 1156 [Note] InnoDB: Doublewrite buffer created
2015-11-16 02:00:39 1156 [Note] InnoDB: 128 rollback segment(s) are active.
2015-11-16 02:00:39 1156 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-11-16 02:00:39 1156 [Note] InnoDB: Foreign key constraint system tables created
2015-11-16 02:00:39 1156 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-11-16 02:00:39 1156 [Note] InnoDB: Tablespace and datafile system tables created.
2015-11-16 02:00:39 1156 [Note] InnoDB: Waiting for purge to start
2015-11-16 02:00:39 1156 [Note] InnoDB: 5.6.16 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2015-11-16 02:00:40 1156 [Note] Binlog end
2015-11-16 02:00:40 1156 [Note] InnoDB: FTS optimize thread exiting.
2015-11-16 02:00:40 1156 [Note] InnoDB: Starting shutdown...
2015-11-16 02:00:41 1156 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2015-11-16 02:00:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-16 02:00:41 1179 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-11-16 02:00:41 1179 [Note] InnoDB: The InnoDB memory heap is disabled
2015-11-16 02:00:41 1179 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-11-16 02:00:41 1179 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-11-16 02:00:41 1179 [Note] InnoDB: Using Linux native AIO
2015-11-16 02:00:41 1179 [Note] InnoDB: Not using CPU crc32 instructions
2015-11-16 02:00:41 1179 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-11-16 02:00:41 1179 [Note] InnoDB: Completed initialization of buffer pool
2015-11-16 02:00:41 1179 [Note] InnoDB: Highest supported file format is Barracuda.
2015-11-16 02:00:41 1179 [Note] InnoDB: 128 rollback segment(s) are active.
2015-11-16 02:00:41 1179 [Note] InnoDB: Waiting for purge to start
2015-11-16 02:00:41 1179 [Note] InnoDB: 5.6.16 started; log sequence number 1625977
2015-11-16 02:00:41 1179 [Note] Binlog end
2015-11-16 02:00:41 1179 [Note] InnoDB: FTS optimize thread exiting.
2015-11-16 02:00:41 1179 [Note] InnoDB: Starting shutdown...
2015-11-16 02:00:43 1179 [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 at http://bugs.mysql.com/

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/.mysql_secret文件里,如图查看初始密码:

 尝试登录MySQL测试下,如图操作:

 提示无法链接,猜测可能是MySQL服务没有启动,执行如下命令启动MySQL服务:

/etc/init.d/mysql start


 然后再登录mysql测试,发现这回登录成功了,如图:

 到这一步说明我们的MySQL已经安装成功了.

使用mysql -V查看安装的MySQL版本:

 

通过RPM包安装MySQL默认在/etc目录下并没有创建my.cnf配置文件,我们需要把/usr/share/mysql目录下的my_deafult.cnf配置文件复制到/etc目录下,并更名为my.cnf,执行命令如下:

cp /usr/share/mysql/my-default.cnf /etc/my.cnf

默认mysql的安装目录如下:

 其中/var/lib/mysql目录就是用于存放mysql的数据文件和日志文件的,即你创建的数据库都是保存在这里,还有mysql数据库的操作日志等.一般建议将这个目录配置到单独的一个自定义目录,因为这个目录需要频繁读写,IO是性能瓶颈,可能需要单独挂载到一个硬盘上.需要在my.cnf里配置我们的自定义数据目录.

 

首先使用mkdir命令创建/data/mysql目录,然后需要把/var/lib/mysql目录下的所有文件全部copy到我们刚刚自定义的/data/mysql目录下,不过操作之前,你需要先通过service mysql stop停掉mysql服务,否则可能会出现文件复制失败:

cp -rap /var/lib/mysql /data/

 然后需要将/data/mysql目录配置到my.cnf里的datadir处,通过vi /etc/my.cnf命令打开my.cnf配置文件进行编辑,如图:

然后通过service mysql start命名重新启动mysql服务,如果mysql服务启动成功,则表明配置没有问题.

 

然后你需要修改mysql默认编码为UTF-8,防止中文乱码,具体操作如图:

 

然后重新启动mysql服务使其生效:service mysql restart

 

贴个完整的my.cnf配置截图,以便你们对照,

 

 

 

设置MySQL服务开机自动启动:

chkconfig mysql on

 

修改MySQL Root帐户的密码:

mysqladmin -u root password '123'

 

删除MySQL系统服务:

chkconfig --del mysql

 

也许是处于MySQL数据库安全考虑,默认MySQL不允许远程访问的,通过以下命令开启远程链接访问:

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION

//使修改生效
mysql>FLUSH PRIVILEGES

 

最后贴下MySQL的my.cnf配置文件的配置项解释说明,以便大家查阅:

[client]  
port = 3306 
socket = /home/mysql/mysql/tmp/mysql.sock  
[mysqld]  
!include /home/mysql/mysql/etc/mysqld.cnf #包含的配置文件 ,把用户名,密码文件单独存放  
port = 3306 
socket = /home/mysql/mysql/tmp/mysql.sock  
pid-file = /longxibendi/mysql/mysql/var/mysql.pid  
basedir = /home/mysql/mysql/  
datadir = /longxibendi/mysql/mysql/var/  
# tmp dir settings  
tmpdir = /home/mysql/mysql/tmp/  
slave-load-tmpdir = /home/mysql/mysql/tmp/  
#当slave 执行 load data infile 时用  
#language = /home/mysql/mysql/share/mysql/english/  
character-sets-dir = /home/mysql/mysql/share/mysql/charsets/  
# skip options  
skip-name-resolve #grant 时,必须使用ip不能使用主机名  
skip-symbolic-links #不能使用连接文件  
skip-external-locking #不使用系统锁定,要使用myisamchk,必须关闭服务器  
skip-slave-start #启动mysql,不启动复制  
#sysdate-is-now  
# res settings  
back_log = 50 #接受队列,对于没建立tcp连接的请求队列放入缓存中,队列大小为back_log,受限制与OS参数  
max_connections = 1000 #最大并发连接数 ,增大该值需要相应增加允许打开的文件描述符数  
max_connect_errors = 10000 #如果某个用户发起的连接error超过该数值,则该用户的下次连接将被阻塞,直到管理员执行flush hosts ; 命令;防止黑客  
#open_files_limit = 10240 
connect-timeout = 10 #连接超时之前的最大秒数,在Linux平台上,该超时也用作等待服务器首次回应的时间  
wait-timeout = 28800 #等待关闭连接的时间  
interactive-timeout = 28800 #关闭连接之前,允许interactive_timeout(取代了wait_timeout)秒的不活动时间。客户端的会话wait_timeout变量被设为会话interactive_timeout变量的值。  
slave-net-timeout = 600 #从服务器也能够处理网络连接中断。但是,只有从服务器超过slave_net_timeout秒没有从主服务器收到数据才通知网络中断  
net_read_timeout = 30 #从服务器读取信息的超时  
net_write_timeout = 60 #从服务器写入信息的超时  
net_retry_count = 10 #如果某个通信端口的读操作中断了,在放弃前重试多次  
net_buffer_length = 16384 #包消息缓冲区初始化为net_buffer_length字节,但需要时可以增长到max_allowed_packet字节  
max_allowed_packet = 64M #  
#table_cache = 512 #所有线程打开的表的数目。增大该值可以增加mysqld需要的文件描述符的数量  
thread_stack = 192K #每个线程的堆栈大小  
thread_cache_size = 20 #线程缓存  
thread_concurrency = 8 #同时运行的线程的数据 此处最好为CPU个数两倍。本机配置为CPU的个数  
# qcache settings  
query_cache_size = 256M #查询缓存大小  
query_cache_limit = 2M #不缓存查询大于该值的结果  
query_cache_min_res_unit = 2K #查询缓存分配的最小块大小  
# default settings  
# time zone  
default-time-zone = system #服务器时区  
character-set-server = utf8 #server级别字符集  
default-storage-engine = InnoDB #默认存储  
# tmp & heap  
tmp_table_size = 512M #临时表大小,如果超过该值,则结果放到磁盘中  
max_heap_table_size = 512M #该变量设置MEMORY (HEAP)表可以增长到的最大空间大小  
log-bin = mysql-bin #这些路径相对于datadir  
log-bin-index = mysql-bin.index  
relayrelay-log = relay-log  
relayrelay_log_index = relay-log.index  
# warning & error log  
log-warnings = 1 
log-error = /home/mysql/mysql/log/mysql.err  
log_output = FILE #参数log_output指定了慢查询输出的格式,默认为FILE,你可以将它设为TABLE,然后就可以查询mysql架构下的slow_log表了  
# slow query log  
slow_query_log = 1 
long-query-time = 1 #慢查询时间 超过1秒则为慢查询  
slow_query_log_file = /home/mysql/mysql/log/slow.log  
#log-queries-not-using-indexes  
#log-slow-slave-statements  
general_log = 1 
general_log_file = /home/mysql/mysql/log/mysql.log  
max_binlog_size = 1G 
max_relay_log_size = 1G 
# if use auto-ex, set to 0  
relay-log-purge = 1 #当不用中继日志时,删除他们。这个操作有SQL线程完成  
# max binlog keeps days  
expire_logs_days = 30 #超过30天的binlog删除  
binlog_cache_size = 1M #session级别  
# replication  
replicate-wild-ignore-table = mysql.% #复制时忽略数据库及表  
replicate-wild-ignore-table = test.% #复制时忽略数据库及表  
# slave_skip_errors=all 
key_buffer_size = 256M #myisam索引buffer,只有key没有data  
sort_buffer_size = 2M #排序buffer大小;线程级别  
read_buffer_size = 2M #以全表扫描(Sequential Scan)方式扫描数据的buffer大小 ;线程级别  
join_buffer_size = 8M # join buffer 大小;线程级别  
read_rnd_buffer_size = 8M #MyISAM以索引扫描(Random Scan)方式扫描数据的buffer大小 ;线程级别  
bulk_insert_buffer_size = 64M #MyISAM 用在块插入优化中的树缓冲区的大小。注释:这是一个per thread的限制  
myisam_sort_buffer_size = 64M #MyISAM 设置恢复表之时使用的缓冲区的尺寸,当在REPAIR TABLE或用CREATE INDEX创建索引或ALTER TABLE过程中排序 MyISAM索引分配的缓冲区  
myisam_max_sort_file_size = 10G #MyISAM 如果临时文件会变得超过索引,不要使用快速排序索引方法来创建一个索引。注释:这个参数以字节的形式给出.重建MyISAM索引(在REPAIR TABLE、ALTER TABLE或LOAD DATA INFILE过程中)时,允许MySQL使用的临时文件的最大空间大小。如果文件的大小超过该值,则使用键值缓存创建索引,要慢得多。该值的单位为字节  
myisam_repair_threads = 1 #如果该值大于1,在Repair by sorting过程中并行创建MyISAM表索引(每个索引在自己的线程内)  
myisam_recover = 64K#允许的GROUP_CONCAT()函数结果的最大长度  
transaction_isolation = REPEATABLE-READ  
innodb_file_per_table  
#innodb_status_file = 1 
#innodb_open_files = 2048 
innodb_additional_mem_pool_size = 100M #帧缓存的控制对象需要从此处申请缓存,所以该值与innodb_buffer_pool对应  
innodb_buffer_pool_size = 2G #包括数据页、索引页、插入缓存、锁信息、自适应哈希所以、数据字典信息  
innodb_data_home_dir = /longxibendi/mysql/mysql/var/  
#innodb_data_file_path = ibdata1:1G:autoextend  
innodb_data_file_path = ibdata1:500M;ibdata2:2210M:autoextend #表空间  
innodb_file_io_threads = 4 #io线程数  
innodb_thread_concurrency = 16 #InnoDB试着在InnoDB内保持操作系统线程的数量少于或等于这个参数给出的限制  
innodb_flush_log_at_trx_commit = 1 #每次commit 日志缓存中的数据刷到磁盘中  
innodb_log_buffer_size = 8M #事物日志缓存  
innodb_log_file_size = 500M #事物日志大小  
#innodb_log_file_size =100M 
innodb_log_files_in_group = 2 #两组事物日志  
innodb_log_group_home_dir = /longxibendi/mysql/mysql/var/#日志组  
innodb_max_dirty_pages_pct = 90 #innodb主线程刷新缓存池中的数据,使脏数据比例小于90%  
innodb_lock_wait_timeout = 50 #InnoDB事务在被回滚之前可以等待一个锁定的超时秒数。InnoDB在它自己的 锁定表中自动检测事务死锁并且回滚事务。InnoDB用LOCK TABLES语句注意到锁定设置。默认值是50秒  
#innodb_flush_method = O_DSYNC 
[mysqldump]  
quick  
max_allowed_packet = 64M 
[mysql]  
disable-auto-rehash #允许通过TAB键提示  
default-character-set = utf8 
connect-timeout = 3 

  

 

 

 

 

 

  • 大小: 33.8 KB
  • 大小: 28.5 KB
  • 大小: 11.7 KB
  • 大小: 12.7 KB
  • 大小: 4.6 KB
  • 大小: 42.7 KB
  • 大小: 7.1 KB
  • 大小: 32.7 KB
  • 大小: 60.9 KB
  • 大小: 66.8 KB
  • 大小: 81.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics