Centos7如何安裝mysql
Centos如何安裝mysql?本教程以Centos7為例,
		本配置適用于centos7版本
1.安裝vim編輯工具
yum install vim -y
				
				
					
				
2.安裝lrzsz上傳工具
yum install lrzsz -y
						
							安裝完后可以使用rz命令上傳所需要的軟件工具(最好進(jìn)入家目錄/home在上傳方便以后查找,關(guān)于如何使用RZ上傳文件,請到幫助中心查看標(biāo)題為centos系統(tǒng)安裝rz使用的教程)
								
								
									
								
									3.指定環(huán)境版本和上傳環(huán)境安裝包
										mysql-5.6.21-linux-glibc2.5-x86_64.tar((具體版本不一定,這邊只是隨機(jī)安裝1個版本,具體看需要什么版本))
4.安裝關(guān)聯(lián)包
yum -y install perl perl-devel yum -y install autoconf //此包安裝時會安裝Data:Dumper模塊 yum -y install libaio* // libaio庫文件
												5.安裝mysql5.6.21
6.進(jìn)入上傳文件目錄解壓mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz文件
[root@vt178m5c home]# tar -zxvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz
7.移動解壓出的mysql文件到/usr/local下重命名為mysql
[root@vt178m5c home]# mv mysql-5.6.21-linux-glibc2.5-x86_64 /usr/local/mysql
8.添加mysql用戶組與用戶名
[root@vt178m5c home]# groupadd mysql [root@vt178m5c home]# useradd -r -g mysql mysql
9.變更mysql文件的用戶權(quán)限為mysql
[root@vt178m5c home]# chown -R mysql:mysql /usr/local/mysql
10.創(chuàng)建數(shù)據(jù)庫數(shù)據(jù)存放路徑
[root@vt178m5c home]# mkdir -p /data/mysql/data
11.進(jìn)入mysql解壓文件
[root@vt178m5c home]# cd /usr/local/mysql
12.安裝初始化數(shù)據(jù)庫,
進(jìn)入scripts文件
[root@vt178m5c mysql]# cd scripts/
初始化數(shù)據(jù)庫,使數(shù)據(jù)庫用戶名為mysql 數(shù)據(jù)庫安裝目錄為/usr/local/mysql 數(shù)據(jù)庫數(shù)據(jù)存放路徑為/data/mysql/data
[root@vt178m5c scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
13.進(jìn)入mysql的support-files文件中
[root@vt178m5c scripts]# cd /usr/local/mysql/support-files
14.復(fù)制my-default.cnf配置文件到/etc下覆蓋掉系統(tǒng)默認(rèn)的my.cnf配置文件
[root@vt178m5c support-files]# cp my-default.cnf /etc/my.cnf
																								
																								
如圖提示是否覆蓋輸入y,回車
																									
																								
15.復(fù)制mysql.server啟動項腳本到/etc/init.d下命名為mysqld
[root@vt178m5c support-files]# cp mysql.server /etc/init.d/mysqld
16.修改啟動項腳本中的兩個變更值
[root@vt178m5c support-files]# vim /etc/init.d/mysqld
找到
																														
																													
修改為
																															
																														
																																	
																																
																																	basedir=/usr/local/mysql //basedir= 數(shù)據(jù)庫程序文件存放地址
datadir=/data/mysql/data //datadir=數(shù)據(jù)庫數(shù)據(jù)存放位置
																																			
																																		
17.配置數(shù)據(jù)庫環(huán)境變量
																																				
																																			
[root@vt178m5c support-files]# vim /etc/profile
在末尾添加
export PATH=$PATH:/usr/local/mysql/bin
																																					
																																					
																																						
																																					
保存退出,更新環(huán)境變量
																																							
																																						
[root@vt178m5c support-files]# source /etc/profile
18.修改mysql配置文件my.cnf
																																								
																																							
[root@vt178m5c support-files]# vim /etc/my.cnf
找到
																																									
																																								
																																									
																																									
																																										
																																									
添加
																																											
																																										
basedir = /usr/local/mysql datadir = /data/mysql/data port = 3306 server_id = 1 socket = /tmp/mysql.sock log-error = /data/mysql/data/mysql-error.log
																																											
																																											
																																												
																																											
19.開啟mysql
																																													
																																												
[root@vt178m5c support-files]# /etc/init.d/mysqld start
mysql開啟成功
																																														
																																													
																																														
																																														
																																															
																																														
20.登入到mysql改密碼
[root@vt178m5c support-files]# mysql -uroot -p
新安裝mysql沒有密碼直接回車即可
																																																	
																																																
																																																	
																																																	
																																																		
																																																	
21.登入成功后設(shè)置mysql密碼
																																																			
																																																		
列:設(shè)置密碼為liut@2018
輸入:
update mysql.user set password=PASSWORD('liut@2018') where user='root';
																																																					
																																																					
																																																						
																																																					
22.刷新權(quán)限表
																																																							
																																																						
輸入:flush privileges;
																																																								
																																																							
																																																								
																																																								
																																																									
																																																								
退出:quit
																																																										
																																																									
																																																										
																																																										
																																																											
																																																										
密碼修改完成,下次登入mysql需要輸入你設(shè)置的密碼
																																																												
																																																											
版權(quán)保護(hù): 本文「Centos7如何安裝mysql」由 云主機(jī)配置專家 原創(chuàng),轉(zhuǎn)載請保留鏈接: http://m.iqcg.cn/docs/system/1130.html

