`

ubuntu下安装mysql

 
阅读更多

MySQL

MySQL is a fast, multi-threaded, multi-user, and robust SQL database server. It is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.

安装

要安装 MySQL,可以在终端提示符后运行下列命令:

sudo apt-get install mysql-server

During the installation process you will be prompted to enter a password for the MySQL root user.

一旦安装完成,MySQL 服务器应该自动启动。您可以在终端提示符后运行以下命令来检查 MySQL 服务器是否正在运行:

 

sudo netstat -tap | grep mysql

 

当您运行该命令时,您可以看到类似下面的行:

tcp        0      0 localhost:mysql         *:*                LISTEN      2556/mysqld

如果服务器不能正常运行,您可以通过下列命令启动它:

sudo service mysql restart

配置(默认是127.0.0.1,只能本机方法)

You can edit the /etc/mysql/my.cnf file to configure the basic settings -- log file, port number, etc. For example, to configure MySQL to listen for connections from network hosts, change the bind-address directive to the server's IP address:

bind-address            = 192.168.0.5

Replace 192.168.0.5 with the appropriate address.

After making a change to /etc/mysql/my.cnf the MySQL daemon will need to be restarted:

sudo service mysql restart

If you would like to change the MySQL root password, in a terminal enter:

sudo dpkg-reconfigure mysql-server-5.5

The MySQL daemon will be stopped, and you will be prompted to enter a new password.

Database Engines

Whilst the default configuration of MySQL provided by the Ubuntu packages is perfectly functional and performs well there are things you may wish to consider before you proceed.

MySQL is designed to allow data to be stored in different ways. These methods are referred to as either database or storage engines. There are two main engines that you'll be interested in: InnoDB and MyISAM. Storage engines are transparent to the end user. MySQL will handle things differently under the surface, but regardless of which storage engine is in use, you will interact with the database in the same way.

Each engine has its own advantages and disadvantages.

While it is possible, and may be advantageous to mix and match database engines on a table level, doing so reduces the effectiveness of the performance tuning you can do as you'll be splitting the resources between two engines instead of dedicating them to one.

  • MyISAM is the older of the two. It can be faster than InnoDB under certain circumstances and favours a read only workload. Some web applications have been tuned around MyISAM (though that's not to imply that they will slow under InnoDB). MyISAM also supports the FULLTEXT data type, which allows very fast searches of large quantities of text data. However MyISAM is only capable of locking an entire table for writing. This means only one process can update a table at a time. As any application that uses the table scales this may prove to be a hindrance. It also lacks journaling, which makes it harder for data to be recovered after a crash. The following link provides some points for consideration about using MyISAM on a production database.

  • InnoDB is a more modern database engine, designed to be ACID compliant which guarantees database transactions are processed reliably. Write locking can occur on a row level basis within a table. That means multiple updates can occur on a single table simultaneously. Data caching is also handled in memory within the database engine, allowing caching on a more efficient row level basis rather than file block. To meet ACID compliance all transactions are journaled independently of the main tables. This allows for much more reliable data recovery as data consistency can be checked.

As of MySQL 5.5 InnoDB is the default engine, and is highly recommended over MyISAM unless you have specific need for features unique to the engine.

Advanced configuration

 

Creating a tuned my.cnf file

There are a number of parameters that can be adjusted within MySQL's configuration file that will allow you to improve the performance of the server over time. For initial set-up you may find Percona's my.cnf generating tool useful. This tool will help generate a my.cnf file that will be much more optimised for your specific server capabilities and your requirements.

Do not replace your existing my.cnf file with Percona's one if you have already loaded data into the database. Some of the changes that will be in the file will be incompatible as they alter how data is stored on the hard disk and you'll be unable to start MySQL. If you do wish to use it and you have existing data, you will need to carry out a mysqldump and reload:

mysqldump --all-databases --routines -u root -p > ~/fulldump.sql
This will then prompt you for the root password before creating a copy of the data. It is advisable to make sure there are no other users or processes using the database whilst this takes place. Depending on how much data you've got in your database, this may take a while. You won't see anything on the screen during this process.

 

Once the dump has been completed, shut down MySQL:

sudo service mysql stop
Now backup the original my.cnf file and replace with the new one:
sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
sudo cp /path/to/new/my.cnf /etc/mysql/my.cnf
Then delete and re-initialise the database space and make sure ownership is correct before restarting MySQL:
sudo rm -rf /var/lib/mysql/*
sudo mysql_install_db
sudo chown -R mysql: /var/lib/mysql
sudo service mysql start
Finally all that's left is to re-import your data. To give us an idea of how far the import process has got you may find the 'Pipe Viewer' utility, pv, useful. The following shows how to install and use pv for this case, but if you'd rather not use it just replace pv with cat in the following command. Ignore any ETA times produced by pv, they're based on the average time taken to handle each row of the file, but the speed of inserting can vary wildly from row to row with mysqldumps:
sudo apt-get install pv
pv ~/fulldump.sql | mysql
Once that is complete all is good to go!

 

This is not necessary for all my.cnf changes. Most of the variables you may wish to change to improve performance are adjustable even whilst the server is running. As with anything, make sure to have a good backup copy of config files and data before making changes.

MySQL Tuner

MySQL Tuner is a useful tool that will connect to a running MySQL instance and offer suggestions for how it can be best configured for your workload. The longer the server has been running for, the better the advice mysqltuner can provide. In a production environment, consider waiting for at least 24 hours before running the tool. You can get install mysqltuner from the Ubuntu repositories:

sudo apt-get install mysqltuner
Then once its been installed, run it:
mysqltuner
and wait for its final report. The top section provides general information about the database server, and the bottom section provides tuning suggestions to alter in your my.cnf. Most of these can be altered live on the server without restarting, look through the official MySQL documentation (link in Resources section) for the relevant variables to change in production. The following is part of an example report from a production database which shows there may be some benefit from increasing the amount of query cache:
-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    key_buffer_size (> 1.4G)
    query_cache_size (> 32M)
    table_cache (> 64)
    innodb_buffer_pool_size (>= 22G)

 

One final comment on tuning databases: Whilst we can broadly say that certain settings are the best, performance can vary from application to application. For example, what works best for Wordpress might not be the best for Drupal, Joomla or proprietary applications. Performance is dependent on the types of queries, use of indexes, how efficient the database design is and so on. You may find it useful to spend some time searching for database tuning tips based on what applications you're using it for. Once you get past a certain point any adjustments you make will only result in minor improvements, and you'll be better off either improving the application, or looking at scaling up your database environment through either using more powerful hardware or by adding slave servers.

资源

 

转载:https://help.ubuntu.com/14.04/serverguide/mysql.html

分享到:
评论

相关推荐

    Ubuntu下安装mysql

    Ubuntu18.0.4安装mysql5.7.25后无法登陆如何处理

    ubuntu 一键安装mysql8

    在Ubuntu系统上一键安装MySQL 8.0是一个方便快捷的过程,尤其对于那些不熟悉Linux命令行操作的用户来说。这个过程通常涉及到下载安装脚本、安装必要的依赖项以及配置MySQL服务。下面将详细介绍如何利用提供的资源...

    ubuntu下安装mysql(网络安装)

    现在的软件越来越好安装,尤其是在ubuntu下安装软件,更是没有技巧,只需要在联网的情况下使用apt-get inatll 即可。在决定安装mysql之前,要先确定系统是否已经安装mysql。

    Ubuntu18.04安装mysql

    ### Ubuntu 18.04 安装 MySQL #### 知识点一:Ubuntu 18.04 系统环境准备 - **系统版本**:Ubuntu 18.04 LTS (Bionic Beaver) 是一个长期支持版本,非常适合部署稳定的服务如 MySQL 数据库。 - **操作系统**:本...

    ubuntu下mysql安装教程

    在Ubuntu系统上安装MySQL是一个相对简单的过程,但对初学者来说可能会遇到一些挑战。这篇教程将引导你逐步完成MySQL的安装,并解决可能出现的问题。MySQL是一个流行的关系型数据库管理系统(RDBMS),广泛应用于Web...

    ubuntu安装mysql5.6完整步骤说明(亲测实用).docx

    Ubuntu 安装 MySQL 5.6 完整步骤说明 在本文中,我们将详细介绍在 Ubuntu 系统中安装 MySQL 5.6 的完整步骤。MySQL 是一个流行的关系数据库管理系统,广泛应用于 Web 应用程序中。本文将涵盖从下载安装包到设置远程...

    ubuntu 下mysql 安装及配置文件

    在Ubuntu系统中安装MySQL是一个常见的任务,特别是在搭建服务器或开发Web应用时。MySQL是一个流行的开源关系型数据库管理系统,被广泛用于存储和管理数据。本文将详细介绍如何在Ubuntu上安装MySQL,以及涉及的配置...

    Ubuntu22-安装mysql5.7

    mysql压缩包

    Ubuntu安装指定版本mysql

    在本文中,我们将详细介绍如何在Ubuntu系统下安装指定版本的MySQL数据库管理系统。MySQL是最流行的开源关系数据库管理系统之一,广泛应用于Web应用程序和企业级应用程序中。下面将一步步地介绍安装过程。 安装准备 ...

    ubuntu20.04安装mysql5.7.42

    在Ubuntu 20.04上安装MySQL 5.7.42的详细步骤 MySQL是一种流行的开源关系型数据库管理系统,被广泛应用于各种规模的项目中。在Ubuntu 20.04上安装MySQL 5.7.42可能与默认的Ubuntu存储库中的最新版本(通常是MySQL 8...

    ubuntu离线安装mysql

    Ubuntu 系统上离线安装 MySQL,这通常适用于那些没有互联网连接或者安全性要求较高的服务器环境。以下是详细的步骤和注意事项: 1、**准备环节** 在一个可以联网的环境中,首先你需要下载 MySQL 的安装包和其依赖...

    ubuntu能用的mysql5.7.38,并附带安装手册

    在Ubuntu操作系统上安装MySQL 5.7.38是一个相对简单的过程,适合那些希望在Linux环境中运行可靠数据库服务的用户。下面将详细介绍在Ubuntu上安装MySQL 5.7.38的步骤以及一些关键知识点。 首先,确保你的Ubuntu系统...

    ubuntu16.04安装mysql5.7脚本

    在Ubuntu 16.04上安装MySQL 5.7是一项常见的系统管理任务,尤其对于开发者和运维人员来说。MySQL 5.7是该数据库管理系统的一个稳定版本,提供了许多性能改进和新特性。以下是关于使用脚本在Ubuntu 16.04上自动安装...

    ubuntu20.04离线安装mysql8.0.30需要的tar包和对应的两个依赖包

    ubuntu20.04离线安装mysql8.0.30需要的tar包和对应的两个依赖包分别是:libaio1和libmecab2,详细的安装步骤请关注博主的另一篇博文

    Ubuntu 安装MySQL(国内镜像源).pdf

    在 Ubuntu 系统中通过国内镜像源安装 MySQL 是一个常见的操作,尤其对于在中国大陆地区的用户来说,使用国内的镜像源可以大大加速下载速度,减少因网络问题导致的安装失败的风险。本文档详细介绍了如何在不同版本的 ...

    Ubuntu中安装mysql-5.7.44-linux-glibc2.12-x86-64.tar.gz

    记事本里完整记录了如何在一台新的ubuntu系统中离线安装mysql数据库,在云服务器上测试成功

    ubuntu12.04安装mysql---黑佳伦.pdf

    在Ubuntu 12.04操作系统中安装MySQL数据库是一个系统性的过程,涉及多个步骤。以下是详细的安装教程: 1. **获取管理员权限**: 在开始安装之前,确保你有管理员权限,可以通过运行`sudo -i`命令切换到超级用户...

    Ubuntu-mysql5.7.25离线完整安装包(含三个依赖包)

    在Linux环境中,特别是Ubuntu系统,有时我们可能需要离线安装MySQL数据库服务器,特别是在没有网络连接或者网络环境受限的服务器上。本教程将详细介绍如何使用提供的"Ubuntu-mysql5.7.25离线完整安装包"来在Ubuntu...

Global site tag (gtag.js) - Google Analytics