Linux MySQL

来源:http://www.cnblogs.com/yinshoucheng-golden/archive/2017/02/25/6441975.html
-Advertisement-
Play Games

MySQL資料庫 第一條產品線:5.0.xx及升級到5.1.xx的產品系列,這條產品線繼續完善與改進其用戶體驗和性能,同時增加新功能。 第二條產品線:為了更好地整合MySQL AB公司社區和第三方公司開發的新存儲引擎,以及吸收新的實現和演算法等,從而更好地支持SMP架構,提高性能而做了大量的代碼重構。... ...


MySQL資料庫

第一條產品線:5.0.xx及升級到5.1.xx的產品系列,這條產品線繼續完善與改進其用戶體驗和性能,同時增加新功能。

第二條產品線:為了更好地整合MySQL AB公司社區和第三方公司開發的新存儲引擎,以及吸收新的實現和演算法等,從而更好地支持SMP架構,提高性能而做了大量的代碼重構。版本編號從5.4.xx開始,目前發展到5.7.xx。

第三條產品線:為了更好地推廣MySQL Cluster版本,以及提高MySQL Cluster的性能和穩定性,以及功能改進和增加,以及改動MySQL基礎功能,使其對Cluster存儲引擎提供更有效的支持與優化。版本號為6.0.xx開始,目前發展到7.1.xx。

安裝MySQL

Linux軟體的安裝方式

1、yum/rpm簡單、快,無法定製,

2、編譯安裝,./configure;make;make install。複雜、數度慢,可定製。

針對mysql,第一條產品線的編譯方式5.0—5.1。

mysql5.5以上,編譯安裝,./cmake;gmake;gmake install。

3、二進位包,解壓即用。簡單、快,不好定製。

mysql-5.5.32-linux2.6-x86_64.tar.gz

  1. [root@lnmp tools]# ls -l mysql-5.5.32-linux2.6-x86_64.tar.gz
  2. -rw-r--r-- 1 root root 186722932 Feb 25 10:17 mysql-5.5.32-linux2.6-x86_64.tar.gz

創建mysql用戶

  1. [root@lnmp tools]# useradd -s /sbin/nologin -M mysql
  2. [root@lnmp tools]# id mysql
  3. uid=503(mysql) gid=503(mysql) groups=503(mysql)

解壓

  1. [root@lnmp tools]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
  2. [root@lnmp tools]# ls -ld mysql-5.5.32-linux2.6-x86_64
  3. drwxr-xr-x 13 root root 4096 Feb 25 10:22 mysql-5.5.32-linux2.6-x86_64

移動到安裝目錄、創建軟連接

  1. [root@lnmp tools]# mv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32
  2. [root@lnmp tools]# cd /application/
  3. [root@lnmp application]# ln -s mysql-5.5.32/ mysql
  4. [root@lnmp application]# ls -l mysql
  5. lrwxrwxrwx 1 root root 13 Feb 25 10:25 mysql -> mysql-5.5.32/

操作到此步驟相當於編譯安裝make install之後。

初始化資料庫

  1. [root@lnmp application]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

授權mysql用戶管理mysql

  1. [root@lnmp application]# chown -R mysql:mysql /application/mysql
  2. [root@lnmp application]# ls -ld /application/mysql
  3. lrwxrwxrwx 1 mysql mysql 13 Feb 25 10:25 /application/mysql -> mysql-5.5.32/

出現兩個OK表示成功

  1. Installing MySQL system tables...
  2. OK
  3. Filling help tables...
  4. OK

生成MySQL配置文件

  1. [root@lnmp mysql]# cp support-files/my-small.cnf /etc/my.cnf

配置啟動MySQL

  1. [root@lnmp mysql]# sed -i "s#/usr/local/mysql#/application/mysql#g" /application/mysql/bin/mysqld_safe

後臺啟動MySQL

  1. [root@lnmp mysql]# /application/mysql/bin/mysqld_safe &
  2. [root@lnmp mysql]# lsof -i:3306
  3. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  4. mysqld 1455 mysql 10u IPv4 16888 0t0 TCP *:mysql (LISTEN)

配置環境變數

  1. [root@lnmp mysql]# vim /etc/profile
  2. PATH="/application/mysql/bin:$PATH"
  3. [root@lnmp mysql]# source /etc/profile
  4. [root@lnmp mysql]# which mysql
  5. /application/mysql/bin/mysql

登錄測試

  1. [root@lnmp mysql]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.5.32 MySQL Community Server (GPL)
  5.  
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7.  
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11.  
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13.  
  14. mysql>

配置傳統方式啟動MySQL

  1. [root@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  2. [root@lnmp mysql]# sed -i "s#/usr/local/mysql#/application/mysql#g" /etc/init.d/mysqld
  3. [root@lnmp mysql]# chmod +x /etc/init.d/mysqld
  4. [root@lnmp mysql]# killall mysqld
  5. [root@lnmp mysql]# lsof -i:3306
  6. [root@lnmp mysql]# /etc/init.d/mysqld start
  7. Starting MySQL.. SUCCESS!
  8. [root@lnmp mysql]# lsof -i:3306
  9. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  10. mysqld 6993 mysql 10u IPv4 21591 0t0 TCP *:mysql (LISTEN)

設置密碼

  1. [root@lnmp mysql]# mysqladmin -uroot password "system"
  2. [root@lnmp mysql]# mysql
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  4. [root@lnmp mysql]# mysql -uroot -psystem
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 3
  7. Server version: 5.5.32 MySQL Community Server (GPL)
  8.  
  9. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  10.  
  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.
  14.  
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  16.  
  17. mysql>

修改密碼

  1. [root@lnmp mysql]# mysqladmin -uroot -psystem password "123456"
  2. [root@lnmp mysql]# mysql -uroot -psystem
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  4. [root@lnmp mysql]# mysql -uroot -p123456
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 7
  7. Server version: 5.5.32 MySQL Community Server (GPL)
  8.  
  9. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  10.  
  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.
  14.  
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  16.  
  17. mysql>

互動式登錄mysql

  1. [root@lnmp mysql]# mysql -uroot -p
  2. Enter password:
  3. mysql> show databases; #查看所有庫
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | mysql |
  9. | performance_schema |
  10. | test |
  11. +--------------------+
  12. 4 rows in set (0.00 sec)
  13.  
  14. mysql> drop database test; #刪除test表
  15. Query OK, 0 rows affected (0.04 sec)
  16.  
  17. mysql> show databases;
  18. +--------------------+
  19. | Database |
  20. +--------------------+
  21. | information_schema |
  22. | mysql |
  23. | performance_schema |
  24. +--------------------+
  25. 3 rows in set (0.00 sec)
  26. mysql> select user,host from mysql.user;
  27. +------+-----------+
  28. | user | host |
  29. +------+-----------+
  30. | root | 127.0.0.1 |
  31. | root | ::1 |
  32. | | lnmp |
  33. | root | lnmp |
  34. | | localhost |
  35. | root | localhost |
  36. +------+-----------+
  37. 6 rows in set (0.03 sec)
  38. mysql> drop user ''@'lnmp'; #刪除用戶
  39. Query OK, 0 rows affected (0.05 sec)
  40. mysql> drop user ''@'localhost';
  41. Query OK, 0 rows affected (0.00 sec)
  42. mysql> drop user 'root'@'lnmp';
  43. Query OK, 0 rows affected (0.00 sec)
  44. mysql> drop user 'root'@'::1';
  45. Query OK, 0 rows affected (0.00 sec)
  46. mysql> select user,host from mysql.user;
  47. +------+-----------+
  48. | user | host |
  49. +------+-----------+
  50. | root | 127.0.0.1 |
  51. | root | localhost |
  52. +------+-----------+
  53. 2 rows in set (0.00 sec)

當有特殊字元或大寫時,使用delete刪除。

  1. mysql> delete from mysql.user where user="root" and host="A";
  2. Query OK, 0 rows affected (0.05 sec)

最後執行刷新,讓許可權生效。

  1. mysql> flush privileges;
  2. Query OK, 0 rows affected (0.00 sec)

查所有的庫:show databases;

切庫:use mysql;

查表:show tables;

查看用戶列表:select user,host from mysql.user;

查看當前用戶:select user();

查看當前所在庫:select database();

刪除資料庫:drop database 庫名;

刪除用戶:drop user '用戶名'@'主機';


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 描述了在window系統下android Studio 中git如何使用Git ...
  • LruCache是一個泛型類,它內部採用LinkedHashMap,並以強引用的方式存儲外界的緩存對象,提供get和put方法來完成緩存的獲取和添加操作。當緩存滿時,LruCache會移除較早的緩存對象,然後再添加新的緩存對象。對Java中四種引用類型還不是特別清楚的讀者可以自行查閱相關資料,這裡不 ...
  • 前言 啦啦啦~各位小伙伴們好~經過這一學期的Android知識的學習,我們學到了很多和Android開發相關的知識,這一學期的學習也要告一段落了。(博客中有很多照片上有代碼,代碼文本較小,各位可按下Ctrl和前滾輪放大後再看~) 一起進入我們今天的相關內容~這次我們將一起學習使用 android 手 ...
  • 寫在前面:當你部署一臺伺服器,第一步不應該是部署應用,安全是才是首要任務 如果某一天當你登錄伺服器發現 /bin/bash –i,python -c 'import pty; pty.spawn("/bin/sh")' 等命令在伺服器上出現的時候,那麼恭喜你,伺服器被入侵了 但是入侵者都是很聰明的, ...
  • ownCloud(官網)是一款開源的私有雲框架,可以通過它實現個人網盤的功能,如果擁有一個性能不錯的VPS,那麼就可以擺脫奇慢無比的百度雲等網盤啦!我花了大約一天的時間總算搭好了ownCloud。 ...
  • 作者信息 作者: 彭東林 郵箱: [email protected] QQ: 405728433 軟體平臺 主機: Ubuntu14.04 64位版本 模擬器:Qemu-2.8.0 Linux內核版本: Linux-4.10 Busybox版本:busybox-1.24.2 工具鏈: ar ...
  • 1、經典入門:hello world 註:上面所使用的關鍵字:include 頭文件包含 int 整型,用來表示整數的類型 void 空類型 return 函數返回 2、基本概念: 源文件:源文件即源程式代碼文件,C語言源文件尾碼名是.c; 頭文件:頭文件的尾碼名為.h,C語言代碼由源文件和頭文件構 ...
  • 第十七節 精簡shell基礎 標簽(空格分隔): Linux實戰教學筆記 1,前言 1.1 為什麼學習shell編程 Shell腳本語言是實現Linux/UNIX系統管理及自動化運維所必備的重要工具,Linux/UNIX系統的底層及基礎應用軟體的核心大部分涉及Shell腳本的內容。每一個合格的Lin ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...