首頁 資料庫 mysql教程 LNMP环境搭建MySQL篇_MySQL

LNMP环境搭建MySQL篇_MySQL

Jun 01, 2016 pm 12:59 PM
環境

1.Install MySQL

<code class="hljs ruby">root@kallen:~# apt-get install mysql-server-5.5 mysql-client-5.5</code>
登入後複製

<strong>2.Add Users</strong>

<strong>(1) 选择数据表</strong><br /> 语句如下:use mysql;<br /> <strong>(2) 在mysql的user表中增加连接用户帐号:</strong><br /> 这里不要直接使用INSERT语句添加user记录,使用INSERT可能出现错误:

ERROR 1364 (HY000): Field &lsquo;ssl_cipher&rsquo; doesn&rsquo;t have a default value

不过早期的MYSQL版本倒没出现这个错误,因为一直都是直接修改user表或直接使用INSERT语句完成,后来升级MYSQL到5.1的时候,发现可能会出现这个错误。<br /> 建议使用GRANT语句进行授权,语句如下:

<code class="hljs ruby"><code class="hljs sql">GRANT USAGE ON *.* TO &#39;username&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;password&#39; WITH GRANT OPTION;</code></code>
登入後複製

<code class="hljs sql">上句:

<code class="hljs sql">&ldquo;username&rdquo;替换为将要授权的用户名,比如clientusr;<br /> &ldquo;password&rdquo;替换为clientusr设置的密码;

<code class="hljs sql">(3) 可访问数据表授权

<code class="hljs sql">创建好帐户之后,就开始给上面的common user进行数据表授权,步骤3中增加的连接用户默认权限都是&ldquo;N&rdquo;的,必须在db表中为该帐户授权,允许其访问专用数据库,当然超级用户就不说了。

<code class="hljs sql">使用下面语句:

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql">GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON tablename.*  TO &#39;username&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;password&#39;;</code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql">本语句中的权限根据实际需要确定:

<code class="hljs sql"><code class="hljs sql">&ldquo;tablename&rdquo;替换为授权访问的数据表table名<br /> &ldquo;username&rdquo; 是步骤2授权用户名<br /> &ldquo;password&rdquo; 是步骤2授权用户的设置密码

<code class="hljs sql"><code class="hljs sql">这样就为该用户授予了对某数据表的SELECT, INSERT, UPDATE, DELETE, CAREATE, DROP权限。

<code class="hljs sql"><code class="hljs sql">(4) 生效授权,创建完毕

<code class="hljs sql"><code class="hljs sql">一句话即可:FLUSH PRIVILEGES;

<code class="hljs sql"><code class="hljs sql"><strong>3.Install phpmyadmin</strong>

<code class="hljs sql"><code class="hljs sql">用随便一个支持PHP的web服务器(如Apache、Nginx、Lighttpd),下载phpmyadmin,装之。

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash">sudo apt-get install phpmyadmin   #注意这是安装到/usr/share/phpmyadmin</code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash">在ubuntu下,sudo apt-getinstall phpmyadmin后会有一些设置,如选择服务器、密码设定等等内容。安装完成后,访问http://localhost/phpmyadmin会出现404错误,这是因为没有将phpmyadmin目录映射到apache目录下面,运行下面命令即可:

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash">sudo ln -s /usr/share/phpmyadmin /var/www/html</code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><strong>[常见错误]</strong>

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><strong>(1) 安装错误:</strong>

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http">Error: Package: php54w-tidy-5.4.41-1.w6.x86_64 (webtatic)

 Requires: libtidy-0.99.so.0()(64bit)

 You could try using --skip-broken to work around the problem

 You could try running: rpm -Va --nofiles --nodigest </code></code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http">需要安装libtidy-0.99.so:

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby">[root@amtt02 html]# rpm -ivh libtidy-0.99.0-19.20070615.1.el6.x86_64.rpm</code></code></code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><strong>(2) 访问错误:</strong><br /> 在http.conf文件中加入:

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><directory phpmyadmin="" share="" usr=""> 

AllowOverride None 

Order allow,deny 

Allow from all 

</directory> </code></code></code></code></code></code></code></code>
登入後複製
<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs ">service httpd restart </code></code></code></code></code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs ">之后,就能成功启动httpd服务了,问题解决。

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs ">访问phpMyAdmin提示:

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs ">配置文件权限错误,无法写入!

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs ">解决办法:

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl">chmod -R 755 ./phpmyadmin</code></code></code></code></code></code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl">这样设置下phpMyAdmin目录权限属性为755就可以访问了。原来phpMyAdmin必须在755权限下才可以运行。

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl">注意:在777下也是错误的,估计是phpMyAdmim为安全着想。

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><strong>4.Can&rsquo;t connect to MySQL server on &lsquo;localhost&rsquo;(10038)</strong>

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl">查一下你的MYSQL用户表里, 是否允许远程连接

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><strong>(1)给用户授权</strong>

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><code class="hljs lasso">mysql>grant all privileges on *.*to&#39;root&#39;@&#39;%&#39;  identified by &#39;youpassword&#39;  with grant option;</code></code></code></code></code></code></code></code></code></code></code>
登入後複製
<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><code class="hljs lasso"><code class="hljs ">mysql>flush privileges;</code></code></code></code></code></code></code></code></code></code></code></code>
登入後複製

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><code class="hljs lasso"><code class="hljs "><strong>(2)修改/etc/mysql/my.conf</strong>

<code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><code class="hljs lasso"><code class="hljs ">找到bind-address =127.0.0.1这一行<br /> 改为bind-address =0.0.0.0 即可

<code class="hljs ruby"><code class="hljs sql"><code class="hljs sql"><code class="hljs bash"><code class="hljs bash"><code class="hljs http"><code class="hljs ruby"><code class="hljs apache"><code class="hljs "><code class="hljs perl"><code class="hljs lasso"><code class="hljs "><code class="hljs vhdl">root@kallen:/etc/selinux# vim /etc/mysql/
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
# Remote Access to MySQL on port 3306
# Kallen Ding, Jun 11 2015
bind-address = 0.0.0.0</code></code></code></code></code></code></code></code></code></code></code></code></code>
登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1318
25
PHP教程
1268
29
C# 教程
1248
24
Python和Anaconda之間有什麼區別? Python和Anaconda之間有什麼區別? Sep 06, 2023 pm 08:37 PM

在本文中,我們將了解Python和Anaconda之間的差異。 Python是什麼? Python是一種開源語言,非常重視使程式碼易於閱讀並透過縮進行和提供空白來理解。 Python的靈活性和易於使用使其非常適用於各種應用,包括但不限於對於科學計算、人工智慧和數據科學,以及創造和發展的線上應用程式。當Python經過測試時,它會立即被翻譯轉化為機器語言,因為它是一種解釋性語言。有些語言,例如C++,需要編譯才能被理解。精通Python是一個重要的優勢,因為它非常易於理解、開發,執行並讀取。這使得Pyth

無法引導到Windows復原環境 無法引導到Windows復原環境 Feb 19, 2024 pm 11:12 PM

Windows復原環境(WinRE)是用來修復Windows作業系統錯誤的環境。進入WinRE後,您可以執行系統還原、出廠重設、卸載更新等操作。如果無法引導到WinRE,本文將指導您使用修復程式解決此問題。無法引導至Windows復原環境如果無法引導至Windows復原環境,請使用下方提供的修復程式:檢查Windows復原環境的狀態使用其他方法進入Windows復原環境您是否意外刪除了Windows復原分割區?執行Windows的就地升級或全新安裝下面,我們已經詳細解釋了所有這些修復。 1]檢查Wi

在 Windows 3 上設定環境變數的 11 種方法 在 Windows 3 上設定環境變數的 11 種方法 Sep 15, 2023 pm 12:21 PM

在Windows11上設定環境變數可以幫助您自訂系統、執行腳本和設定應用程式。在本指南中,我們將討論三種方法以及逐步說明,以便您可以根據自己的喜好配置系統。有三種類型的環境變數系統環境變數–全域變數處於最低優先權,可由Windows上的所有使用者和應用程式訪問,通常用於定義系統範圍的設定。使用者環境變數–優先順序越高,這些變數僅適用於在該帳戶下執行的目前使用者和進程,並由在該帳戶下執行的使用者或應用程式設定。進程環境變數–具有最高優先權,它們是臨時的,適用於當前進程及其子進程,為程式提供

php整合環境包有哪些 php整合環境包有哪些 Jul 24, 2023 am 09:36 AM

php整合環境套件有:1、PhpStorm,功能強大的PHP整合環境;2、Eclipse,開放原始碼的整合開發環境;3、Visual Studio Code,輕量級的開源程式碼編輯器;4、Sublime Text,受歡迎的文本編輯器,廣泛用於各種程式語言;5、NetBeans,由Apache軟體基金會開發的整合開發環境;6、Zend Studio,為PHP開發者設計的整合開發環境。

Laravel環境設定檔.env的常見問題及解決方法 Laravel環境設定檔.env的常見問題及解決方法 Mar 10, 2024 pm 12:51 PM

Laravel環境設定檔.env的常見問題及解決方法在使用Laravel框架開發專案時,環境設定檔.env是非常重要的,它包含了專案的關鍵配置信息,如資料庫連接資訊、應用程式金鑰等。然而,有時在配置.env檔案時會出現一些常見問題,本文將針對這些問題進行介紹並提供解決方法,同時附上具體的程式碼範例供參考。問題一:無法讀取.env檔當我們設定好了.env文件

Python web開發環境搭建教程 Python web開發環境搭建教程 Jun 17, 2023 pm 02:10 PM

Python是一種高階程式語言,由於它跨平台、簡單易學、功能強大等特性,一些大型公司,如Google、Dropbox等都選擇使用Python進行開發。隨著最近幾年來Web應用程式逐漸成為主流應用,Python也逐漸成為了Web應用程式的首選開發語言。本文將介紹如何在Windows系統上建置PythonWeb開發環境,包含Pyth

go語言環境如何配置 go語言環境如何配置 Jan 06, 2021 am 11:37 AM

go語言環境配置方法:1、下載go語言的編譯器,雙擊運行安裝程式;2、接受許可協議,點選next;3、設定安裝目錄,點選OK;4、安裝完成後,將go安裝目錄下的bin目錄加入環境變數中即可。

簡單刪除Conda環境:高效率清理無用環境的技巧 簡單刪除Conda環境:高效率清理無用環境的技巧 Jan 04, 2024 am 08:15 AM

一鍵刪除Conda環境:快速清理無用環境的技巧隨著資料科學和機器學習的快速發展,使用Python進行開發和分析的需求也越來越強烈。 Conda作為一種流行的Python套件管理器和環境管理工具,被廣泛應用於專案開發和環境配置中。然而,隨著時間的推移,我們常常會在電腦上留下許多無用的Conda環境,這不僅浪費了磁碟空間,還可能導致環境混亂和不必要的麻煩。本文將介

See all articles