我安装的是 mysql-8.0.19-winx64 使用 管理员运行 CMD ,否则会报 Install/Remove of the Service Denied! 进入系统盘找到C:\Windows\System32\cmd.exe右键以管理员身份运行 再次进入相应目录执行 mysqld -install 显示Service successfully installed
windows下安装mysql-8.0.18-winx64的教程(图文详解) https://www.jb51.net/article/176452.htm
<div id="content"> <p><strong>1、下载安装包</strong></p> <p>安装包现在地址:</p> <p><a href="https://dev.mysql.com/downloads/mysql/">https://dev.mysql.com/downloads/mysql/</a></p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250541.jpg"></p> <p><strong>2、解压缩至安装目录</strong></p> <p>解压缩下载之后的zip,我这里使用的安装路径为:</p> <p>C:\Program Files\mysql-8.0.18-winx64</p> <p>解压缩之后,需要在安装路径下手动创建data文件夹以及my.ini文件</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250542.jpg"></p> <p>3、配置my.ini文件</p> <p>编辑my.ini文件的内容</p> <div class="jb51code"> <div><div id="highlighter_6068" class="syntaxhighlighter sql"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="sql plain">[mysqld]</code></div><div class="line number2 index1 alt1"><code class="sql plain"># 设置3306端口</code></div><div class="line number3 index2 alt2"><code class="sql plain">port=3306</code></div><div class="line number4 index3 alt1"><code class="sql plain"># 设置mysql的安装目录</code></div><div class="line number5 index4 alt2"><code class="sql plain">basedir=C:\Program Files\mysql-8.0.18-winx64</code></div><div class="line number6 index5 alt1"><code class="sql plain"># 设置mysql数据库的数据的存放目录</code></div><div class="line number7 index6 alt2"><code class="sql plain">datadir=C:\Program Files\mysql-8.0.18-winx64\data</code></div><div class="line number8 index7 alt1"><code class="sql plain"># 允许最大连接数</code></div><div class="line number9 index8 alt2"><code class="sql plain">max_connections=200</code></div><div class="line number10 index9 alt1"><code class="sql plain"># 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统</code></div><div class="line number11 index10 alt2"><code class="sql plain">max_connect_errors=10</code></div><div class="line number12 index11 alt1"><code class="sql plain"># 服务端使用的字符集默认为UTF8</code></div><div class="line number13 index12 alt2"><code class="sql keyword">character</code><code class="sql plain">-</code><code class="sql keyword">set</code><code class="sql plain">-server=utf8</code></div><div class="line number14 index13 alt1"><code class="sql plain"># 创建新表时将使用的默认存储引擎</code></div><div class="line number15 index14 alt2"><code class="sql keyword">default</code><code class="sql plain">-storage-engine=INNODB</code></div><div class="line number16 index15 alt1"><code class="sql plain"># 默认使用“mysql_native_password”插件认证</code></div><div class="line number17 index16 alt2"><code class="sql plain">default_authentication_plugin=mysql_native_password</code></div><div class="line number18 index17 alt1"><code class="sql plain">[mysql]</code></div><div class="line number19 index18 alt2"><code class="sql plain"># 设置mysql客户端默认字符集</code></div><div class="line number20 index19 alt1"><code class="sql keyword">default</code><code class="sql plain">-</code><code class="sql keyword">character</code><code class="sql plain">-</code><code class="sql keyword">set</code><code class="sql plain">=utf8</code></div><div class="line number21 index20 alt2"><code class="sql plain">[client]</code></div><div class="line number22 index21 alt1"><code class="sql plain"># 设置mysql客户端连接服务端时默认使用的端口</code></div><div class="line number23 index22 alt2"><code class="sql plain">port=3306</code></div><div class="line number24 index23 alt1"><code class="sql keyword">default</code><code class="sql plain">-</code><code class="sql keyword">character</code><code class="sql plain">-</code><code class="sql keyword">set</code><code class="sql plain">=utf8</code></div></div></td></tr></tbody></table></div></div> </div> <p>小贴士:</p> <p>记得my.ini文件格式要是ANSI格式,否则会报这种错误。</p> <blockquote> <p>Found option without preceding group in config file</p> </blockquote> <p><strong>4、初始化并启动mysql服务</strong></p> <p>使用管理员身份 运行cmd命令,</p> <p>进入C:\Program Files\mysql-8.0.18-winx64目录</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250543.jpg"></p> <div class="jb51code"> <div><div id="highlighter_898920" class="syntaxhighlighter sql"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="sql comments">--初始化,会打印数据库密码,记住该密码,后面会用到</code></div><div class="line number2 index1 alt1"><code class="sql plain">mysqld </code><code class="sql comments">--initialize --console</code></div><div class="line number3 index2 alt2"><code class="sql spaces"> </code> </div><div class="line number4 index3 alt1"><code class="sql comments">--这里MySql8是服务的名字,你可以不写或者自己命名一个服务</code></div><div class="line number5 index4 alt2"><code class="sql plain">mysqld </code><code class="sql comments">--install localmysql</code></div><div class="line number6 index5 alt1"><code class="sql spaces"> </code> </div><div class="line number7 index6 alt2"><code class="sql comments">--这里是启动服务名字,就是刚刚命名的名字</code></div><div class="line number8 index7 alt1"><code class="sql plain">net start localmysql</code></div><div class="line number9 index8 alt2"><code class="sql spaces"> </code> </div><div class="line number10 index9 alt1"><code class="sql comments">--登陆数据库,这时会让你输入密码</code></div><div class="line number11 index10 alt2"><code class="sql plain">mysql -u root -p</code></div><div class="line number12 index11 alt1"><code class="sql spaces"> </code> </div><div class="line number13 index12 alt2"><code class="sql comments">--密码过于难记,修改密码为:123456</code></div><div class="line number14 index13 alt1"><code class="sql keyword">set</code> <code class="sql keyword">password</code> <code class="sql keyword">for</code> <code class="sql plain">root@localhost=</code><code class="sql string">'123456'</code><code class="sql plain">;</code></div><div class="line number15 index14 alt2"><code class="sql spaces"> </code> </div><div class="line number16 index15 alt1"><code class="sql comments">--显示所以数据库</code></div><div class="line number17 index16 alt2"><code class="sql plain">show databases;</code></div></div></td></tr></tbody></table></div></div> </div> <p>初始密码是下面这个字符串。</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250544.jpg"></p> <p><strong>5、安装验证</strong></p> <p>验证</p> <p>1、在进程中有mysql的进程</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250545.jpg"></p> <p>验证</p> <p>2、使用navicat可以连接到数据库中</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250546.jpg"></p> <p>6、创建数据库并运行指定sql文件</p> <div class="jb51code"> <div><div id="highlighter_310223" class="syntaxhighlighter plain"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="plain plain">mysql -u root -p</code></div><div class="line number2 index1 alt1"><code class="plain plain">create database rexel_hzzg;</code></div></div></td></tr></tbody></table></div></div> </div> <p>执行sql文件</p> <p>在mysql控制台之外执行</p> <p>C:\Program Files\mysql-8.0.18-winx64\bin>mysql -uroot -p123456 -Drexel_hzzg<D:\rexel\sql\rexel_hzzg.sql</p> <p style="text-align: center"><img alt="" src="//files.jb51.net/file_images/article/201912/2019121610250547.jpg"></p> <p><strong>7、停止mysql进程</strong></p> <p><strong>方式一:</strong></p> <p><code>net stop mysql</code>(这样关闭的前题是安装了服务);</p> <p><strong>方式二:</strong></p> <p><code>mysqladmin -u root shutdown</code>(在设置了密码的情况下的命令为mysqladmin -u root -p shutdown)</p> <p><span style="color: #ff0000"><strong>总结</strong></span></p> <p>以上所述是小编给大家介绍的windows下安装mysql-8.0.18-winx64的教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!<br> 如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!</p> </div>
来源:oschina
链接:https://my.oschina.net/u/4312139/blog/4120429