{"id":62295,"date":"2024-10-13T17:49:24","date_gmt":"2024-10-13T09:49:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/62295\/"},"modified":"2024-10-13T17:49:24","modified_gmt":"2024-10-13T09:49:24","slug":"linux%e5%b9%b3%e5%8f%b0mysql%e7%9a%84%e5%ae%89%e8%a3%9d%e9%85%8d%e7%bd%ae%e4%b9%8b%e5%b8%b8%e7%94%a8%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/62295\/","title":{"rendered":"Linux\u5e73\u53f0mysql\u7684\u5b89\u88dd\u914d\u7f6e\u4e4b\u5e38\u7528\u64cd\u4f5c"},"content":{"rendered":"<h1 id=\"linux%e5%b9%b3%e5%8f%b0mysql%e7%9a%84%e5%ae%89%e8%a3%9d%e9%85%8d%e7%bd%ae%e4%b9%8b%e5%b8%b8%e7%94%a8%e6%93%8d%e4%bd%9c-PHIYaOeBrH\">Linux\u5e73\u53f0MySQL\u7684\u5b89\u88dd\u914d\u7f6e\u4e4b\u5e38\u7528\u64cd\u4f5c<\/h1>\n<p>MySQL\u662f\u4e00\u6b3e\u6d41\u884c\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2eWeb\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5728Linux\u5e73\u53f0\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u7684\u5e38\u7528\u64cd\u4f5c\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7ba1\u7406\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9dmysql-PHIYaOeBrH\">\u4e00\u3001\u5b89\u88ddMySQL<\/h2>\n<p>\u5728Linux\u7cfb\u7d71\u4e0a\u5b89\u88ddMySQL\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u57fa\u65bcUbuntu\u548cCentOS\u7684\u5b89\u88dd\u6b65\u9a5f\u3002<\/p>\n<h3 id=\"1-%e5%9c%a8ubuntu%e4%b8%8a%e5%ae%89%e8%a3%9dmysql-PHIYaOeBrH\">1. \u5728Ubuntu\u4e0a\u5b89\u88ddMySQL<\/h3>\n<pre><code>sudo apt update\nsudo apt install mysql-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysql\nsudo systemctl enable mysql\n<\/code><\/pre>\n<h3 id=\"2-%e5%9c%a8centos%e4%b8%8a%e5%ae%89%e8%a3%9dmysql-PHIYaOeBrH\">2. \u5728CentOS\u4e0a\u5b89\u88ddMySQL<\/h3>\n<pre><code>sudo yum update\nsudo yum install mysql-server\n<\/code><\/pre>\n<p>\u540c\u6a23\uff0c\u5b89\u88dd\u5b8c\u6210\u5f8c\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysqld\nsudo systemctl enable mysqld\n<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e9%85%8d%e7%bd%aemysql-PHIYaOeBrH\">\u4e8c\u3001\u914d\u7f6eMySQL<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u9032\u884c\u57fa\u672c\u7684\u914d\u7f6e\u662f\u5fc5\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u914d\u7f6e\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"1-%e5%ae%89%e5%85%a8%e9%85%8d%e7%bd%ae-PHIYaOeBrH\">1. \u5b89\u5168\u914d\u7f6e<\/h3>\n<p>MySQL\u63d0\u4f9b\u4e86\u4e00\u500b\u5b89\u5168\u8173\u672c\u4f86\u5e6b\u52a9\u7528\u6236\u9032\u884c\u57fa\u672c\u7684\u5b89\u5168\u914d\u7f6e\u3002\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>\u9019\u500b\u8173\u672c\u6703\u5f15\u5c0e\u7528\u6236\u8a2d\u7f6eroot\u5bc6\u78bc\u3001\u522a\u9664\u533f\u540d\u7528\u6236\u3001\u7981\u6b62root\u9060\u7a0b\u767b\u9304\u4ee5\u53ca\u522a\u9664\u6e2c\u8a66\u6578\u64da\u5eab\u7b49\u3002<\/p>\n<h3 id=\"2-%e7%99%bb%e9%8c%84mysql-PHIYaOeBrH\">2. \u767b\u9304MySQL<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p\n<\/code><\/pre>\n<p>\u7cfb\u7d71\u6703\u63d0\u793a\u8f38\u5165\u5bc6\u78bc\uff0c\u8f38\u5165\u5f8c\u5373\u53ef\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-PHIYaOeBrH\">3. \u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h3>\n<p>\u5728MySQL\u4e2d\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database;\nCREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n<p>\u9019\u4e9b\u547d\u4ee4\u5c07\u5275\u5efa\u4e00\u500b\u540d\u70bamy_database\u7684\u6578\u64da\u5eab\u548c\u4e00\u500b\u7528\u6236my_user\uff0c\u4e26\u6388\u4e88\u8a72\u7528\u6236\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u6240\u6709\u6b0a\u9650\u3002<\/p>\n<h2 id=\"%e4%b8%89%e3%80%81%e5%b8%b8%e7%94%a8%e6%93%8d%e4%bd%9c-PHIYaOeBrH\">\u4e09\u3001\u5e38\u7528\u64cd\u4f5c<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5728MySQL\u4e2d\u5e38\u7528\u7684\u64cd\u4f5c\u547d\u4ee4\uff1a<\/p>\n<h3 id=\"1-%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab-PHIYaOeBrH\">1. \u67e5\u770b\u6578\u64da\u5eab<\/h3>\n<pre><code>SHOW DATABASES;\n<\/code><\/pre>\n<h3 id=\"2-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a%e5%ba%ab-PHIYaOeBrH\">2. \u522a\u9664\u6578\u64da\u5eab<\/h3>\n<pre><code>DROP DATABASE my_database;\n<\/code><\/pre>\n<h3 id=\"3-%e6%9f%a5%e7%9c%8b%e8%a1%a8%e6%a0%bc-PHIYaOeBrH\">3. \u67e5\u770b\u8868\u683c<\/h3>\n<pre><code>USE my_database;\nSHOW TABLES;\n<\/code><\/pre>\n<h3 id=\"4-%e5%89%b5%e5%bb%ba%e8%a1%a8%e6%a0%bc-PHIYaOeBrH\">4. \u5275\u5efa\u8868\u683c<\/h3>\n<pre><code>CREATE TABLE my_table (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(100) NOT NULL,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\n<\/code><\/pre>\n<h3 id=\"5-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-PHIYaOeBrH\">5. \u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>INSERT INTO my_table (name) VALUES ('Sample Name');\n<\/code><\/pre>\n<h3 id=\"6-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-PHIYaOeBrH\">6. \u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>SELECT * FROM my_table;\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-PHIYaOeBrH\">\u7e3d\u7d50<\/h2>\n<p>\u5728Linux\u5e73\u53f0\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u7528\u6236\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u4e26\u9032\u884c\u6578\u64da\u5eab\u7ba1\u7406\u3002\u7121\u8ad6\u662f\u5275\u5efa\u6578\u64da\u5eab\u3001\u7528\u6236\uff0c\u9084\u662f\u9032\u884c\u6578\u64da\u64cd\u4f5c\uff0c\u9019\u4e9b\u57fa\u672c\u547d\u4ee4\u90fd\u80fd\u5e6b\u52a9\u7528\u6236\u9ad8\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72\u60a8\u7684MySQL\u670d\u52d9\uff0c\u4eab\u53d7\u66f4\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Linux\u5e73\u53f0\u4e0aMySQL\u7684\u5b89\u88c5\u4e0e\u914d\u7f6e\uff0c\u638c\u63e1\u5e38\u7528\u64cd\u4f5c\uff0c\u63d0\u5347\u6570\u636e\u5e93\u7ba1\u7406\u6548\u7387\u4e0e\u6027\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-62295","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=62295"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62295\/revisions"}],"predecessor-version":[{"id":62296,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62295\/revisions\/62296"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=62295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=62295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=62295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}