search
HomeDatabaseMysql TutorialUbuntu 12.04下安装MySQL

今天在Ubuntu12.04上面使用二进制tar.gz文件安装成功,现总结如下: 首先到mysql的下载中心上下载最新的tar.gz包: 1.链接地址为http://www.mysql.com/downloads/,我下载的 是mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz。 然后将其解压,并重命名为mysql,

今天在Ubuntu12.04上面使用二进制tar.gz文件安装成功,现总结如下:


首先到mysql的下载中心上下载最新的tar.gz包:

1.链接地址为http://www.mysql.com/downloads/,我下载的 是mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz。

然后将其解压,并重命名为mysql,使用mv命令将其移到/usr/local目录下:

将上面的做好了后,就可以进入mysql的安装了,mysql默认的安装目录就是在/usr/local/mysql;如果在机器上以前安装有老板本的mysql,需要先将它的文件删除,同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配置属性。

按上面的记叙我可以知,先要创建的一个名为mysql的用户组和用户,来承载mysql数据库的运行,使用如下命令:

创建用户组:

sudo groupadd mysql 

在创建的用户组中创建一个用户:

sudo useradd -r -g mysql mysql 

这里使用sudo命令是确保以root权限执行此命令。


接着进入mysql目录,修改mysql目录的拥有者,为mysql用户:

进入目录:

cd /usr/local/mysql

修改目录的拥有者:

sudo chown -R mysql .

sudo chgrp -R mysql .

这里的点“.”代表的就是当前目录,选项-R表示递归当前目录及其子目录。

现在安装mysql,执行命令:

sudo scripts/mysql_install_db --user=mysql

其实,这一步正真的目地就是生成一些mysql数据库运行的系统数据库。

注意:在Ubuntu12.04下安装mysql 执行此命令时,会提示如下错误的信息:

./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

这说明还要安装一个libaio的依赖库,执行如下命令:

sudo apt-get install libaio-dev

安装完libaio后,继续执行“sudo  scripts/mysql_install_db --user=mysql”命令来进行安装。(一定要在mysql目录下执行,注意输出的文字,里边有修改root密码和启动mysql的命令)

执行完上面的命令后,其实就已经完成了mysql的安装,但为了数据库的安全,可以将mysql目录的拥有者改为root用户,并将生成的系统依赖数据赋给mysql用户,执行如下命令:

chown -R root .

chown -R mysql data

安装好mysql后,就可以试着启动它,使用如下命令:

sudo ./support-files/mysql.server start 

同样重启和停止,只需要将上面命令的start改为restart或stop。

为root设置密码: ./bin/mysqladmin -u root

启动完mysql后,我们接着可以测试一下,使用“./bin/mysql”命令来进入mysql数据库的控制台,执行SQL命令。

为了数据库的安全我们需要为数据库访问设置密码,可以执行如下命令,将mysql的配置文件安装到/etc目录下:


这样设置好后,进入mysql的控制台,则需要使用如下命令:

sudo ./bin/mysql -uroot -p

show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

发现已有四个表,mysql安装成功。



PS:使用Navicat for MySQL连接主机上的mysql时报错:

ERROR 1130: Host '***' is not allowed to connect to MySQL server

解决方法:
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -p

use mysql;

update user set host = '%' where user = 'root';

select host, user from user;

2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;




Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.