{"id":64,"date":"2018-04-11T19:32:40","date_gmt":"2018-04-11T11:32:40","guid":{"rendered":"http:\/\/esufy.com\/?p=64"},"modified":"2024-03-10T15:44:48","modified_gmt":"2024-03-10T07:44:48","slug":"linux%e4%b8%8b%e5%ae%89%e8%a3%85mysql","status":"publish","type":"post","link":"http:\/\/www.esufy.cn\/?p=64","title":{"rendered":"linux\u4e0b\u5b89\u88c5mysql"},"content":{"rendered":"<p><strong>\u5b98\u65b9\u6587\u6863\uff1a<\/strong><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/binary-installation.html\" target=\"_blank\" rel=\"noopener\">Installing MySQL on Unix\/Linux Using Generic Binaries<\/a><br \/>\n<strong>1\u3001\u4e0b\u8f7d<\/strong><br \/>\n<code>[root@localhost soft]# wget https:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.7\/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz<\/code><br \/>\n<strong>2\u3001\u89e3\u538b\u6587\u4ef6<\/strong><br \/>\n<code>[root@dbserver \/]# tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C \/usr\/local\/<\/code><br \/>\n<strong>3\u3001\u4fee\u6539\u6587\u4ef6<\/strong><br \/>\n<code>[root@dbserver local]# mv mysql-5.7.19-linux-glibc2.12-x86_64 mysql<\/code><br \/>\n<strong>4\u3001\u68c0\u67e5\u5e93\u6587\u4ef6\u662f\u5426\u6709\u5220\u9664\uff0c\u82e5\u6709\u4fbf\u5220\u9664\uff08linux\u7cfb\u7edf\u81ea\u5e26\u7684\uff09<\/strong><br \/>\n<code>[root@dbserver mysql]# rpm -qa | grep mysql<\/code><br \/>\n\u5220\u9664<br \/>\n<code>[root@dbserver mysql]# rm -e \u2013-nodeps mysql-libs-5.1.52.x86_64<\/code><br \/>\n<strong>5\u3001\u7531\u4e8eMySQL\u8fd0\u884c\u9700\u8981libaio\u5e93\uff0c\u6240\u4ee5\u9700\u8981\u5148\u8fdb\u884c\u5b89\u88c5\uff1a<\/strong><br \/>\n<code>[root@localhost soft]# yum install libaio<\/code><br \/>\n<strong>6\u3001\u68c0\u67e5mysql\u7ec4\u548c\u7528\u6237\u662f\u5426\u5b58\u5728\uff0c\u5982\u65e0\u521b\u5efa<\/strong><br \/>\n<code>[root@dbserver ~]# cat \/etc\/group | grep mysql<br \/>\n[root@dbserver ~]# cat \/etc\/passwd |grep mysql<\/code><br \/>\n\u521b\u5efa<br \/>\n<code>[root@dbserver ~]#groupadd mysql<br \/>\n[root@dbserver ~]#useradd -r -g mysql mysql<\/code><br \/>\n\/\/useradd -r\u53c2\u6570\u8868\u793amysql\u7528\u6237\u662f\u7cfb\u7edf\u7528\u6237\uff0c\u4e0d\u53ef\u7528\u4e8e\u767b\u5f55\u7cfb\u7edf<br \/>\n<strong>7\u3001\u5728mysql\u4e0b\u6dfb\u52a0data\u76ee\u5f55<\/strong><br \/>\n<code>[root@dbserver mysql]# mkdir data<\/code><br \/>\n<strong>8\u3001\u66f4\u6539mysql\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u76ee\u5f55\u53ca\u6587\u4ef6\u5939\u6240\u5c5e\u7ec4\u5408\u7528\u6237<\/strong><br \/>\n<code>[root@dbserver mysql]# cd \/usr\/local\/<br \/>\n[root@dbserver local]# chown -R mysql mysql\/<br \/>\n[root@dbserver local]# chgrp -R mysql mysql\/<br \/>\n[root@dbserver local]# cd mysql\/<br \/>\n[root@dbserver mysql]# ls -l<br \/>\ntotal 40<br \/>\ndrwxr-xr-x. 2 mysql mysql 4096 Aug 31 16:45 bin<br \/>\n-rw-r--r--. 1 mysql mysql 17987 Jun 22 22:13 COPYING<br \/>\ndrwxr-xr-x. 2 mysql mysql 6 Aug 31 16:48 data<br \/>\ndrwxr-xr-x. 2 mysql mysql 52 Aug 31 16:45 docs<br \/>\ndrwxr-xr-x. 3 mysql mysql 4096 Aug 31 16:44 include<br \/>\ndrwxr-xr-x. 5 mysql mysql 4096 Aug 31 16:45 lib<br \/>\ndrwxr-xr-x. 4 mysql mysql 28 Aug 31 16:45 man<br \/>\n-rw-r--r--. 1 mysql mysql 2478 Jun 22 22:13 README<br \/>\ndrwxr-xr-x. 28 mysql mysql 4096 Aug 31 16:45 share<br \/>\ndrwxr-xr-x. 2 mysql mysql 86 Aug 31 16:45 support-files<\/code><br \/>\n<strong>9\u3001\u5b89\u88c5\u548c\u521d\u59cb\u5316\u6570\u636e\u5e93<\/strong><br \/>\n\u5b89\u88c5<br \/>\n<code>[root@dbserver bin]# .\/mysqld --initialize --user=mysql --basedir=\/usr\/local\/mysql\/ --datadir=\/usr\/local\/mysql\/data\/ --lc_messages_dir=\/usr\/local\/mysql\/share --lc_messages=en_US<br \/>\n2017-08-31T09:00:54.941514Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).<br \/>\n2017-08-31T09:00:56.364312Z 0 [Warning] InnoDB: New log files created, LSN=457902017-08-31T09:00:56.602211Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.<br \/>\n2017-08-31T09:00:56.668145Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e69986d2-8e2a-11e7-a335-<br \/>\n005056b427be.2017-08-31T09:00:56.671464Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-08-31T09:00:56.672453Z 1 [Note] A temporary password is generated for root@localhost: qfuqvCsHb2!.<\/code><br \/>\n<strong>10\u3001\u914d\u7f6emy.cnf<\/strong><br \/>\n\u63a5\u4e0b\u6765\u8fdb\u5165\/usr\/local\/mysql\/support-files\/\u76ee\u5f55\u4e0b<br \/>\n\u67e5\u770b\u662f\u5426\u5b58\u5728my-default.cnf\u6587\u4ef6\uff0c\u5982\u679c\u5b58\u5728\u76f4\u63a5copy\u5230\/etc\/my.cnf\u6587\u4ef6\u4e2d<br \/>\n<code>[root@dbserver mysql]# cp -a .\/support-files\/my-default.cnf \/etc\/my.cnf<\/code><br \/>\n\u5982\u679c\u4e0d\u5b58\u5728my-default.cnf\u6587\u4ef6,\u5219\u5728\/etc\/\u76ee\u5f55\u4e0b\u521b\u5efamy.cnf,\u5e76\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9<br \/>\n<code>#[mysql] #basedir=\/usr\/local\/mysql\/ #datadir=\/usr\/local\/mysql\/data\/<\/code><br \/>\n<strong>11\u3001\u542f\u52a8\u670d\u52a1<\/strong><br \/>\n<code>[root@dbserver mysql]# cd bin\/<br \/>\n[root@dbserver bin]# .\/mysqld_safe --user=mysql &amp;<br \/>\n[2] 10436<br \/>\n[root@dbserver bin]# Logging to '\/var\/log\/mysql\/mysql.log'.2017-08-31T09:52:15.806633Z mysqld_safe Starting mysqld daemon with databases from \/var\/lib\/mysql<br \/>\n2017-08-31T09:52:16.292949Z mysqld_safe mysqld from pid file \/var\/run\/mysql\/mysql.pid ended<\/code><br \/>\n<strong>12\u3001\u5c06mysqld\u670d\u52a1\u52a0\u5165\u5f00\u673a\u81ea\u542f\u52a8\u9879\u3002<\/strong><br \/>\n\u5c06{mysql}\/ support-files\/mysql.server \u62f7\u8d1d\u4e3a\/etc\/init.d\/mysql\u5e76\u8bbe\u7f6e\u8fd0\u884c\u6743\u9650\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4f7f\u7528service mysql\u547d\u4ee4\u542f\u52a8\/\u505c\u6b62\u670d\u52a1\uff0c<br \/>\n\u5426\u5219\u5c31\u53ea\u80fd\u4f7f\u7528{mysql}\/bin\/mysqld_safe &amp;\u547d\u4ee4\u6765\u542f\u52a8\u670d\u52a1<br \/>\n\u8fd8\u9700\u8981\u628amysql.server\u4e2dbasedir\u7684\u76f8\u5173\u8def\u5f84\uff0c\u6539\u4e3a\u81ea\u5b9a\u4e49\u7684\u8def\u5f84\uff0c\u9ed8\u8ba4\u8def\u5f84\u662f\/usr\/local\/mysql<br \/>\n<code>[root@dbserver support-files]# cp mysql.server \/etc\/init.d\/mysql<br \/>\n[root@dbserver support-files]# chmod +x \/etc\/init.d\/mysql -- \u628amysql\u6ce8\u518c\u4e3a\u5f00\u673a\u542f\u52a8\u7684\u670d\u52a1<br \/>\n[root@dbserver support-files]# chkconfig --add mysql -- \u67e5\u770b\u662f\u5426\u6dfb\u52a0\u6210\u529f<br \/>\n[root@dbserver support-files]# chkconfig --list mysql<br \/>\nNote: This output shows SysV services only and does not include native<br \/>\nsystemd services. SysV configuration data might be overridden by native<br \/>\nsystemd configuration.<\/code><br \/>\nIf you want to list systemd services use &#8216;systemctl list-unit-files&#8217;.<br \/>\nTo see services enabled on particular target use<br \/>\n&#8216;systemctl list-dependencies [target]&#8217;.<br \/>\nmysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off<br \/>\n<strong>13\u3001\u542f\u52a8\u670d\u52a1<\/strong><br \/>\n<code>[root@dbserver bin]# service mysql start<br \/>\nStarting MySQL.Logging to '\/var\/log\/mysql\/mysql.log'.<br \/>\nERROR! The server quit without updating PID file (\/var\/lib\/mysql\/dbserver.pid).<\/code><br \/>\n\u89e3\u51b3<br \/>\n<code>[root@dbserver mysql]# rm \/etc\/my.cnfrm: remove regular file '\/etc\/my.cnf'? y<br \/>\n[root@dbserver mysql]# \/etc\/init.d\/mysql start Starting MySQL.Logging to '\/usr\/local\/mysql\/data\/dbserver.err'.<br \/>\nSUCCESS!<br \/>\n[root@dbserver mysql]# service mysql startStarting MySQL SUCCESS!<\/code><br \/>\n<strong>14\u3001\u767b\u5f55mysql<\/strong><br \/>\n<code>[root@dbserver bin]# .\/mysql -u root -p<\/code><br \/>\n\u5bc6\u7801\u662f\u7b2c\u516b\u6b65\u4ea7\u751f\u7684\u5bc6\u7801<br \/>\n<strong>15\u3001\u8bbe\u7f6e\u5bc6\u7801<\/strong><br \/>\n<code>mysql&gt; set password=password(\"root\");<br \/>\nQuery OK, 0 rows affected, 1 warning (0.00 sec)<\/code><br \/>\n<strong>16\u3001\u8bbe\u7f6e\u8fdc\u7a0b\u767b\u5f55\u6743\u9650<\/strong><br \/>\n<code>mysql&gt; grant all privileges on *.* to'root' @'%' identified by 'root';<br \/>\nQuery OK, 0 rows affected, 1 warning (0.00 sec)<\/code><br \/>\n<code>mysql&gt; flush privileges;<br \/>\nQuery OK, 0 rows affected (0.06 sec)<\/code><br \/>\n<code>mysql&gt; quit;<\/code><br \/>\n\u81f3\u6b64\uff0cmysql\u5b89\u88c5\u3001\u914d\u7f6e\u5b8c\u6210\u3002<br \/>\nLinux\u8fde\u63a5mysql\u62a5\u9519\uff1aAccess denied for user \u2018root\u2019@\u2018%\u2019(using password: YES)\u7684\u89e3\u51b3\u65b9\u6cd5<br \/>\n1.\u5148\u505c\u6b62mysql \u670d\u52a1<br \/>\n<code>service mysqld stop<\/code><br \/>\n2.\u8fdb\u5165mysql\u5b89\u88c5\u76ee\u5f55bin\/ \u4f7f\u7528safe\u6a21\u5f0f\uff0c\u8fdb\u884c\u91cd\u542f\uff1a<br \/>\n<code>.\/mysqld_safe --skip-grant-tables<\/code><br \/>\n3.\u4f7f\u7528root\u8d26\u6237\uff0c\u65e0\u5bc6\u7801\u767b\u5f55\uff0c\u4fee\u6539root\u7528\u6237\u5bc6\u7801<br \/>\n<code>mysql -u root<br \/>\nuse mysql;<br \/>\nupdate user set authentication_string=PASSWORD(\"\u4f60\u7684\u5bc6\u7801\") where User = 'root';<br \/>\nflush privileges;<br \/>\nquit;<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9\u6587\u6863\uff1aInstalling MySQL on Unix\/Linux Using Generic Binar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":300,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,24],"tags":[10],"_links":{"self":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/64"}],"collection":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64"}],"version-history":[{"count":1,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":162,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions\/162"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/media\/300"}],"wp:attachment":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}