Linux下安装mysql
本文内容纲要:
首先,linux下有多种方法,①为编译的,②编译的tar.gz包,③,编译的rpm;本文打算叙述rpm形式的安装过程:后边将书tar.gz包的安装及一些问题的解决参考
一、下载安装包
官方网站下载,或者百度云链接下载:
MySQL-server-5.7.4_m14-1.el6.x86_64.rpm
MySQL-client-5.7.4_m14-1.el6.x86_64.rpm
二、检查与清理原来是否有安装残留
如果确信没有安装过mysql服务就不用了,如果是重装或者不确定可以逐级查看
如果有用yum安装过使用命令:yumremovemysql*卸载
然后删除mysql旧有的文件和文件夹残留或者数据,:
rm-rfmysql****
杀死mysqld进程kill-9mysqld
特别注意:/etc/my.cnf文件、/usr/bin、/usr/share下的mysql相关的文件也要一并删除,此外还有安装过程中的/etc/init.d/mysql配置文件的删除
三、安装rpm包及解决可能出现的依赖
安装一中下载的rpm文件,先安装server.prm文件,然后安装client.rpm文件
rpm-ivh文件名.rpm
[root@localhost/]#rpm-ivhMySQL-server-5.7.4_m14-1.el6.x86_64.rpm
error:Faileddependencies:
net-toolsisneededbyMySQL-server-5.7.4_m14-1.el6.x86_64
学要解决net-tools依赖,可以参考:yum解决依赖关系,中的
YUM常见命令用法如下:
1.列出所有可更新的软件清单,命令:yumcheck-update软件名称
2.安装所有更新软件,命令:yumupdate软件名称
3.仅安装指定的软件,命令:yuminstall软件名称
4.列出所有可安裝的软件清单,命令:yumlist
5.用YUM安装删除软件,命令:yumremove软件名称
简单使用:yuminstallnet-tools然后y同意即可,但是后便会有点小问题看见Complete!才算是安装net-tools成功
后边再执行rpm-ivhxxx.rpm后看见一堆冲突:
file/usr/share/mysql/charsets/READMEfrominstallofMySQL-server-5.7.4_m14-1.el6.x86_64conflictswithfilefrompackagemariadb-libs-1:5.5.47-1.el7_2.x86_64
……
file/usr/share/mysql/czech/errmsg.sysfrominstallofMySQL-server-5.7.4_m14-1.el6.x86_64conflictswithfilefrompackagemariadb-libs-1:5.5.47-1.el7_2.x86_64
很简单,就是之前的文件没有删除干净,重新检查,删除一下。
之前我自己用有用yum安装过mariadb-libs-1:5.5.47-1.el7_2.x86_64,所以用上变得命令yumremovemariadb-libs-1:5.5.47-1.el7_2.x86_64删除这个包mariadb-libs-1:5.5.47-1.el7_2.x86_64
然后再执行rpm-ivhXXX
Preparing...#################################[100%]
find:'/var/lib/mysql':Nosuchfileordirectory
Updating/installing...
1:MySQL-server-5.7.4_m14-1.el6#################################[100%]
ARANDOMPASSWORDHASBEENSETFORTHEMySQLrootUSER!
Youwillfindthatpasswordin'/root/.mysql_secret'.
Youmustchangethatpasswordonyourfirstconnect,
nootherstatementbut'SETPASSWORD'willbeaccepted.
Seethemanualforthesemanticsofthe'passwordexpired'flag.
留意上边的修改密码提示。
然后安装client:
[root@localhost/]#rpm-ivhMySQL-client-5.7.4_m14-1.el6.x86_64.rpm
Preparing...#################################[100%]
Updating/installing...
1:MySQL-client-5.7.4_m14-1.el6#################################[100%]
四、设置密码与简单使用
查看服务是否启动,即3306端口是否在启动:netstat-nat
启动服务:servicemysqlstart
[root@localhost/]#servicemysqlstart
StartingMySQL..ERROR!TheserverquitwithoutupdatingPIDfile(/var/lib/mysql/localhost.localdomain.pid).
[root@localhost/]#servicemysqlrestart
ERROR!MySQLserverPIDfilecouldnotbefound!
StartingMySQL..ERROR!TheserverquitwithoutupdatingPIDfile(/var/lib/mysql/localhost.localdomain.pid).
还是原来的问题,还是原来的提示,这酸爽!!!
进入提示的文件夹,果然没有那个pid文件,然后vimlocalhost.localdomain.err查看问题没有什么有用的信息。
简直是,执行rpm-qlMySQL-server-5.7.4_m14-1.el6.x86_64.rpm
packageMySQL-server-5.7.4_m14-1.el6.x86_64.rpmisnotinstalled显示的是未安装???
[root@localhost/]#servicemysqlstart
StartingMySQL..ERROR!TheserverquitwithoutupdatingPIDfile(/var/lib/mysql/localhost.localdomain.pid).
查资料说有僵尸进程:参考使用命令:ps-aux|grepmysqld显示如下:
root25910.00.38984808pts/0S+03:440:00grep--color=automysqld
然后执行ps-aux的会看到个字段的意思。
USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND
杀掉进程:kill-9进程号
但是还是启动不了:第二中种没用
终极tie我想笑:丢失了pid怎么办最终自己新建了一个/var/lib/mysql/localhost.localdomain.pid文件,里边直接写入ps-aux|grepmysqld读到的pid值,保存就行。
[root@localhostmysql]#servicemysqlstart
StartingMySQLSUCCESS!
然而:netstat-nat还是查询不到33006端口,再次启动还是是失败。
登录:
五、卸载
------------
tar.gz形式的安装。
一、下载安装包
二、创建mysql用户
三、安装数据库
[root@localhostsever]#cdmysql-5.7.11
[root@localhostmysql-5.7.11]#cdbin
[root@localhostbin]#./mysql_install_db--user=mysql--basedir=/home/mysql/--datadir=/home/mysql/data
2016-04-0422:09:05[WARNING]mysql_install_dbisdeprecated.Pleaseconsiderswitchingtomysqld--initialize
2016-04-0422:09:06[ERROR]Childprocess:/usr/sever/mysql-5.7.11/bin/mysqldterminatedprematurelywitherrno=32
2016-04-0422:09:06[ERROR]Failedtoexecute/usr/sever/mysql-5.7.11/bin/mysqld--bootstrap--datadir=/home/mysql/data--lc-messages-dir=/usr/share/mysql--lc-messages=en_US--basedir=/home/mysql
--serverlogbegin--
2016-04-05T02:09:05.358823Z0[Warning]--bootstrapisdeprecated.Pleaseconsiderusing--initializeinstead
2016-04-05T02:09:05.359564Z0[Warning]Changedlimits:max_open_files:4096(requested5000)
2016-04-05T02:09:05.359573Z0[Warning]Changedlimits:table_open_cache:1967(requested2000)
2016-04-05T02:09:05.360209Z0[ERROR]Can'treadfrommessagefile'/usr/share/mysql/english/errmsg.sys'
--serverlogend--
[root@localhostbin]#./mysqld--user=mysql--basedir=/home/mysql/--datadir=/home/mysql/data
2016-04-05T02:10:35.847170Z0[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails).
2016-04-05T02:10:35.847260Z0[Warning]Insecureconfigurationfor--secure-file-priv:Currentvaluedoesnotrestrictlocationofgeneratedfiles.Considersettingittoavalid,non-emptypath.
2016-04-05T02:10:35.847293Z0[Note]./mysqld(mysqld5.7.11)startingasprocess16732...
2016-04-05T02:10:35.847327Z0[ERROR]Can'tfinderror-messagefile'/home/mysql/share/errmsg.sys'.Checkerror-messagefilelocationand'lc-messages-dir'configurationdirective.
2016-04-05T02:10:35.850131Z0[ERROR]
2016-04-05T02:10:35.850147Z0[ERROR]Couldn'tloadpluginnamed'keyring_file'withsoname'keyring_file.so'.
2016-04-05T02:10:35.850690Z0[Note]InnoDB:PUNCHHOLEsupportnotavailable
2016-04-05T02:10:35.850832Z0[Note]InnoDB:Mutexesandrw_locksuseGCCatomicbuiltins
2016-04-05T02:10:35.850842Z0[Note]InnoDB:Useseventmutexes
2016-04-05T02:10:35.850848Z0[Note]InnoDB:GCCbuiltin__sync_synchronize()isusedformemorybarrier
2016-04-05T02:10:35.850852Z0[Note]InnoDB:Compressedtablesusezlib1.2.3
2016-04-05T02:10:35.850858Z0[Note]InnoDB:UsingLinuxnativeAIO
2016-04-05T02:10:35.851146Z0[Note]InnoDB:Numberofpools:1
2016-04-05T02:10:35.851259Z0[Note]InnoDB:UsingCPUcrc32instructions
2016-04-05T02:10:35.860704Z0[Note]InnoDB:Initializingbufferpool,totalsize=128M,instances=1,chunksize=128M
2016-04-05T02:10:35.871080Z0[Note]InnoDB:Completedinitializationofbufferpool
2016-04-05T02:10:35.873518Z0[ERROR][FATAL]InnoDB:pthread_createreturned11
2016-04-0422:10:350x7f7a8aa26740InnoDB:Assertionfailureinthread140164288636736infileut0ut.ccline920
InnoDB:Weintentionallygenerateamemorytrap.
InnoDB:Submitadetailedbugreporttohttp://bugs.mysql.com.
InnoDB:Ifyougetrepeatedassertionfailuresorcrashes,even
InnoDB:immediatelyafterthemysqldstartup,theremaybe
InnoDB:corruptionintheInnoDBtablespace.Pleasereferto
InnoDB:http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
InnoDB:aboutforcingrecovery.
02:10:35UTC-mysqldgotsignal6;
Thiscouldbebecauseyouhitabug.Itisalsopossiblethatthisbinary
oroneofthelibrariesitwaslinkedagainstiscorrupt,improperlybuilt,
ormisconfigured.Thiserrorcanalsobecausedbymalfunctioninghardware.
Attemptingtocollectsomeinformationthatcouldhelpdiagnosetheproblem.
Asthisisacrashandsomethingisdefinitelywrong,theinformation
collectionprocessmightfail.
key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
Itispossiblethatmysqldcoulduseupto
key_buffer_size+(read_buffer_size+sort_buffer_size)*max_threads=68188Kbytesofmemory
Hopethat'sok;ifnot,decreasesomevariablesintheequation.
Threadpointer:0x0
Attemptingbacktrace.Youcanusethefollowinginformationtofindout
wheremysqlddied.Ifyouseenomessagesafterthis,somethingwent
terriblywrong...
stack_bottom=0thread_stack0x40000
./mysqld(my_print_stacktrace+0x35)[0xf45595]
./mysqld(handle_fatal_signal+0x4a4)[0x77fd34]
/lib64/libpthread.so.0(+0xf130)[0x7f7a8a606130]
/lib64/libc.so.6(gsignal+0x37)[0x7f7a892075d7]
/lib64/libc.so.6(abort+0x148)[0x7f7a89208cc8]
./mysqld[0x10dd465]
./mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x10e2b33]
./mysqld(_Z21os_thread_create_funcPFPvS_ES_Pm+0x277)[0xff3d37]
./mysqld(_Z34innobase_start_or_create_for_mysqlv+0x1686)[0x1097196]
./mysqld[0xf7669d]
./mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x7caac1]
./mysqld[0xd35576]
./mysqld(_Z11plugin_initPiPPci+0x965)[0xd3a3c5]
./mysqld[0x77641b]
./mysqld(_Z11mysqld_mainiPPc+0x516)[0x779316]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f7a891f3af5]
./mysqld[0x76fdc9]
Themanualpageathttp://dev.mysql.com/doc/mysql/en/crashing.htmlcontains
informationthatshouldhelpyoufindoutwhatiscausingthecrash.
四、配置文件
[root@localhostmysql-5.7.11]#cdsupport-files/
[root@localhostsupport-files]#cpmy-default.cnf/etc/my.cnf
cp:overwrite'/etc/my.cnf'?yes
[root@localhostsupport-files]#cpmysql.server/etc/init.d/mysql
[root@localhostsupport-files]#vim/etc/init.d/mysql
#!/bin/sh
#!/bin/sh
#CopyrightAbandoned1996TCXDataKonsultAB&MontyProgramKB&DetronHB
#ThisfileispublicdomainandcomeswithNOWARRANTYofanykind
#MySQLdaemonstart/stopscript.
#Usuallythisisputin/etc/init.d(atleastonmachinesSYSVR4based
#systems)andlinkedto/etc/rc3.d/S99mysqland/etc/rc0.d/K01mysql.
#Whenthisisdonethemysqlserverwillbestartedwhenthemachineis
#startedandshutdownwhenthesystemsgoesdown.
#CommentstosupportchkconfigonRedHatLinux
#chkconfig:23456436
#description:AveryfastandreliableSQLdatabaseengine.
#CommentstosupportLSBinitscriptconventions
###BEGININITINFO
#Provides:mysql
#Required-Start:$local_fs$network$remote_fs
#Should-Start:ypbindnscdldapntpdxntpd
#Required-Stop:$local_fs$network$remote_fs
#Default-Start:2345
#Default-Stop:016
#Short-Description:startandstopMySQL
#Description:MySQLisaveryfastandreliableSQLdatabaseengine.
###ENDINITINFO
#IfyouinstallMySQLonsomeotherplacesthan/usr/local/mysql,thenyou
#havetodooneofthefollowingthingsforthisscripttowork:
#
#-RunthisscriptfromwithintheMySQLinstallationdirectory
#-Createa/etc/my.cnffilewiththefollowinginformation:
#[mysqld]
#basedir=
#-Addtheabovetoanyotherconfigurationfile(forexample~/.my.ini)
#andcopymy_print_defaultsto/usr/bin
#-Addthepathtothemysql-installation-directorytothebasedirvariable
#below.
#
#IfyouwanttoaffectotherMySQLvariables,youshouldmakeyourchanges
#inthe/etc/my.cnf,~/.my.cnforotherMySQLconfigurationfiles.
#Ifyouchangebasedir,youmustalsochangedatadir.Thesemayget
#overwrittenbysettingsintheMySQLconfigurationfiles.
basedir=/home/mysql/
datadir=/home/mysql/data
#Defaultvalue,inseconds,afterwhichthescriptshouldtimeoutwaiting
#forserverstart.
#Valuehereisoverridenbyvalueinmy.cnf.
#0meansdon'twaitatall
#Negativenumbersmeantowaitindefinitely
service_startup_timeout=900
#LockdirectoryforRedHat/SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
#Thefollowingvariablesareonlysetforlettingmysql.serverfindthings.
五、配置环境变量
vi.bash_profile
#Userspecificenvironmentandstartupprograms
exportMYSQL_HOME="/home/mysql/mysql-5.7.9"
exportPATH="$PATH:$MYSQL_HOME/bin"
六、添加开机启动服务
chkconfig--addmysql
chkconfigmysqlon
七、启动mysql
[root@localhost~]#su-mysql
[mysql@localhost~]$servicemysqlstart
StartingMySQLERROR!Couldn'tfindMySQLserver(/home/mysql//bin/mysqld_safe)
(果然出错了)~~~~~
basedir=/usr/sever/mysql-5.7.11/
datadir=/home/mysql/data
然后修改到末尾出现:
E45:'readonly'optionisset(add!tooverride)
按照网上的解决方案:ESC后输入:wq!,(参考链接)
强制保存后,显示的错误
"/etc/rc.d/init.d/mysql"
"/etc/rc.d/init.d/mysql"E212:Can'topenfileforwriting
Enter后,继续ESC:x显示
E505:"/etc/rc.d/init.d/mysql"isread-only(add!tooverride)
(如果仍旧不能保存退出的话,就重启开启以个连接修改试试,可能会出现--bash-4.2问题),上变得不能够编辑的问题可能是由于我在[mysql@localhost~]路径下修改文件原因。
参考链接:linux下安装mysql.tar.gz
---------------------
4/4/16测试安装,然后后边几天一直在断断续续解决tar.gz七中的问题
注意学习和解决问题的效率
4/6/16问题解决过程中发现没有/home/mysql/data/下根本就没有pid文件,重新安装rpm版本,补充
本文内容总结:
原文链接:https://www.cnblogs.com/mxh1099/p/5347809.html