搜尋
首頁資料庫mysql教程[Linux基础环境/软件]Linux下安装mysql

我是使用免安装的包mysql-5.5.28-linux2.6-x86_64.tar.gz(在http://dev.mysql.com/downloads/可以下载到最新的包)的。直接解压,然后配置,初始化数据库,启动即可。

安装步骤有:
  1. 解压和建立软链;
  2. 配置文件和配置参数;
  3. 初始化数据库;
  4. 启动和关闭;
  5. 建立数据库用户和授权。
 

1. 解压和建立软链:

#tar xzvf mysql-5.5.28-linux2.6-x86_64.tar.gz#在/usr/local目录下#ln -s mysql-5.5.28-linux2.6-x86_64 mysql#创建软链
 

2. 配置文件和配置参数:

mysql会将默认的配置文件保存在mysql/support-files/下。我们把mysql/support-files/my-medium.cnf 复制一份到/etc下然后进行配置。

#cp usr/local/mysql/support-files/my-medium.cnf etc/my.cnf

在my.cnf文件添加相关配置,下面红色部分是我修改和添加的内容,相关目录根据自己的需要配置。

[client]
default-character-set = utf8
# password      = your_passsword
port            = 3306
socket          = /tmp/mysql_3306.sock
# The MySQL server
[mysqld]
character-set-server = utf8
# user            = mysql
port            = 3306
socket          = /tmp/mysql_3306.sock
skip-external-locking
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/log/mysql_error.log
pid-file = /tmp/mysql.pid
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64

 

3. 初始化数据库:

mysql自带了mysql和test两个数据库。而mysql-5.5.28-linux2.6-x86_64.tar.gz包是没有初始化的。所以我们先要初始化。在mysql/bin或者mysql/scripts下有个 mysql_install_db 可执行文件,执行即可(要保证其无报错)。

#./mysql_install_db--verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --tmpdir=/tmp
 

4. 启动和关闭:

执行bin/mysqld_safe 文件可以启动mysql。

#./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql_3306.sock --user=root &

之前我在没有初始化的时候执行启动,遇到了报错,报错内容会在my.cnf的log-error配置路径下。上面最后的“&”表示后台执行的意思。

 

关闭mysql可以直接kill掉进程,也可以使用bin/mysqladmin可执行文件操作。

#./mysqladmin -u root -p [密码] shutdown
 

5. 建立数据库用户和授权:

在bin/里面执行mysql文件,连接数据库。

#./mysql -uroot

连接成功之后可以创建一个数据库用户,供远程访问,你总不能用root去访问数据库吧。另外还要设置其权限,譬如建表、建库、增删查改。grant可以修改用户的权限和密码。

 建立用户:
mysql>CREATE USER [用户名] IDENTIFIED BY '[密码]';mysql>CREATE USER [用户名]@[固定登录地址(譬如localhost)] IDENTIFIED BY '[密码]'
授权:
mysql>GRANT select, insert, update, delete, create ON *.* TO [用户名];mysql>GRANT select, insert, update, delete, create ON *.* TO [用户名]@[固定登录地址(譬如localhost)];
修改密码:
mysql>GRANT ALL PRIVILEGES ON PUREFTPD.* TO [用户名] IDENTIFIED BY '[新密码]';
 6. 测试:

这样在PC端也可以用管理工具访问了。

 //------------//共勉之
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存儲斑點安全嗎?mysql:存儲斑點安全嗎?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通過PHP Web界面添加用戶mySQL:通過PHP Web界面添加用戶May 14, 2025 am 12:04 AM

通過PHP網頁界面添加MySQL用戶可以使用MySQLi擴展。步驟如下:1.連接MySQL數據庫,使用MySQLi擴展。 2.創建用戶,使用CREATEUSER語句,並使用PASSWORD()函數加密密碼。 3.防止SQL注入,使用mysqli_real_escape_string()函數處理用戶輸入。 4.為新用戶分配權限,使用GRANT語句。

mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

See all articles

熱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

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

熱門文章

熱工具

SublimeText3 Mac版

SublimeText3 Mac版

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

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用