Ubuntu12.04下安装Mysql
下面就个人这几天在ubunt12.04下安装mysql做一个总结: 在linux下安装mysql有三种方式:第一种以rpm的二进制文件分个安装,第二种是自己编译源码后安装,最后一种是以二进制tar.gz文件来安装。 这三种中,由于最后一种是统一的整体文件,个人感觉最简单,故
下面就个人这几天在ubunt12.04下安装mysql做一个总结:
在linux下安装mysql有三种方式:第一种以rpm的二进制文件分个安装,第二种是自己编译源码后安装,最后一种是以二进制tar.gz文件来安装。
这三种中,由于最后一种是统一的整体文件,个人感觉最简单,故本文将采用此方式来进行安装:
首先到mysql的下载中心上下载最新的tar.gz包:
1.在浏览器中输入http://www.mysql.com/downloads/,进入mysql的下载中心,在这里有使用mysql开发的一些工具,包括mysql的驱动,数据库以及图形开发工具MySQL Workbench等。在这里我们选择MySQL Community Server链接,进入mysql 数据库服务器的下载:
如上,点击“MySQL Community Server”链接进入下载页面,接着选择myql的平台,选择Linux - Generic平台:
然后在其中选择二进制tar.gz文件形式的文件进行下载:
选择32位或64位的下载,这里选择32位的,下载后得到文件mysql-5.5.28-linux2.6-i686.tar.gz,然后将其解压,并重命名为mysql,使用mv命令将其移到/usr/local目录下:
sudo mv ~/下载/mysql /usr/local
提示:其中文本文件INSTALL-BINARY详细的记录了mysql在Linux下的安装方法,英文好的同鞋可以直接的查看。
将上面的做好了后,我们现在就可以进入mysql的安装了,根据INSTALL-BINARY文件的描述,可知mysql默认的安装目录就是在/usr/local/mysql,这就是上面为什么我们要将其移动在/uer/local下的原因;如果在你的机器上以前安装有老板本的mysql,需要先将它的文件删除,同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配置属性。
按上面的记叙我可以知,先要创建的一个名为mysql的用户组和用户,来承载mysql数据库的运行,使用如下命令:
创建用户组:
sudo groupadd mysql
sudo useradd -r -g mysql mysql
题外话:对应删除用户组及用户的命令是groupdel和userdel。
接着进入mysql目录,修改mysql目录的拥有者,为mysql用户:
进入目录:
cd /usr/local/mysql
修改目录的拥有者:
sudo chown -R mysql . sudo chgrp -R mysql .
这里的点“.”代表的就是当前目录,选项-R表示递归当前目录及其子目录。
现在真正的进入主题,安装mysql,执行命令:
sudo scripts/mysql_install_db --user=mysql
注意:在ubuntu 12.04下安装mysql 5.5.28版本执行此命令时,会提示如下错误的信息:
./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
执行完上面的命令后,其实就已经完成了mysql的安装,但为了数据库的安全,可以将mysql目录的拥有者改为root用户,并将生成的系统依赖数据赋给mysql用户,执行如下命令:
chown -R root . chown -R mysql data
安装好mysql后,就可以试着启动它,使用如下命令:
sudo ./support-files/mysql.server start
启动完mysql后,我们接着可以测试一下,使用“./bin/mysql”命令来进入mysql数据库的控制台,执行SQL命令。
为了数据库的安全我们需要为数据库访问设置密码,可以执行如下命令,将mysql的配置文件安装到/etc目录下:
sudo cp support-files/my-medium.cnf /etc/my.cnf
这样设置好后,进入mysql的控制台,则需要使用如下命令:
sudo ./bin/mysql -uroot -p
提示输入密码后,就可以进入控制台了。
最后:
上面介绍的这么多,总结mysql的安装实际上只需执行“sudo ./scripts/mysql_install_db --user=系统用户名“这一条命令,这里设置的系统用户可以直接的使用当前登入系统用户,在linux中查看当前用户的命令是:
who am i
ln -s <mysql> /usr/local/mysql</mysql>
basedir=<mysql> datadir=<mysql>/data</mysql></mysql>
在启动mysql时,还可以使用如下命令:
sudo ./bin/mysqld_safe --user=mysql &
sudo ./bin/mysqladmin -u root -p password '新密码'
提示输入旧数据库的密码后,密码才变更为新密码。
为了确保数据库中支持中文,可以修改/etc/my.cnf文件:
在[client]段下添加
default-character-set = utf8
character_set_server = utf8
安装好mysql后,就可以安装mysql的图形化客服端MySQL Workbench了,可以到http://www.mysql.com/downloads/workbench/下选择合适的版本下载,在上面有ubuntu下的版本,下载后的文件为BED格式,双击后可以直接安装十分方便。
如果在安装好MySQL Workbench后,出现运行mysql.server start无法启动的情况,可以查看一下,是否存在/etc/mysql目录,如果有要将其删除;同时还要检查/etc/my.cnf文件的内容。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
