Debian Linux安装MySQL数据库服务器

时间:2020-01-09 10:40:09  来源:igfitidea点击:

如何在HP服务器上运行的Debian Linux操作系统上安装mysql数据库服务器?
如何在Debian或Ubuntu服务器上安装MySQL?

MySQL是一种功能强大且流行的数据库管理系统,适用于Linux和Unix等操作系统。
您需要在Debian上安装以下软件包:

  • mysql-server在Debian上安装最新的稳定的MySQL数据库服务器二进制文件和系统数据库设置。
  • mysql-client安装最新的稳定的MySQL数据库客户端二进制文件。

在Debian Linux上安装MySQL服务器+客户端

首先,您需要执行以下apt-get命令或aptitude命令以使Debian保持最新状态:

# aptitude update && aptitude upgrade

或者

# apt-get update && apt-get upgrade

安装MySQL

使用ssh客户端打开终端或登录到远程服务器。
执行以下apt-get命令以安装MySQL:

# apt-get install mysql-server mysql-client

输出示例:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libxcb-render-util0-dev xulrunner-1.9.1 libxcb-render-util0
Use 'apt-get autoremove' to remove them.
Selecting previously deselected package libnet-daemon-perl.
(Reading database ... 159847 files and directories currently installed.)
Unpacking libnet-daemon-perl (from .../libnet-daemon-perl_0.43-1_all.deb) ...
Selecting previously deselected package libplrpc-perl.
Unpacking libplrpc-perl (from .../libplrpc-perl_0.2020-2_all.deb) ...
Selecting previously deselected package libdbi-perl.
Unpacking libdbi-perl (from .../libdbi-perl_1.612-1_amd64.deb) ...
Selecting previously deselected package libdbd-mysql-perl.
Unpacking libdbd-mysql-perl (from .../libdbd-mysql-perl_4.016-1_amd64.deb) ...
Selecting previously deselected package mysql-client-5.1.
Unpacking mysql-client-5.1 (from .../mysql-client-5.1_5.1.49-3_amd64.deb) ...
Selecting previously deselected package mysql-server-core-5.1.
Unpacking mysql-server-core-5.1 (from .../mysql-server-core-5.1_5.1.49-3_amd64.deb) ...
...
,...

在安装过程中,将提示您设置mysql admin root用户的密码:
设置admin root用户密码
设置root用户密码
安装完成警告:如果不要求您输入MySQL root用户在安装期间输入密码,执行以下命令以在Debian Linux上设置/更改MySQL超级用户密码:mysqladmin -u超级密码NEWPASSWORDNameHere

如何启动/停止/重新启动MySQL Server?

MySql将在启动时启动。
您还可以以root用户身份执行以下命令来启动/停止/重新启动服务器:

# /etc/init.d/mysql start
# /etc/init.d/mysql stop
# /etc/init.d/mysql restart
# /etc/init.d/mysql status

或者

# service mysql start
# service mysql stop
# service mysql restart
# service mysql status

MySQL服务器配置

MySQL数据库服务器配置文件位于/etc/mysql/my.cnf。
使用文本编辑器(例如vi)编辑文件,执行:

# vi /etc/mysql/my.cnf

输出示例:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
 
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
 
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0
 
[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/english
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
#
# * Fine Tuning
#
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
 
 
 
[mysqldump]
quick
quote-names
max_allowed_packet      = 16M
 
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
 
[isamchk]
key_buffer              = 16M
 
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

如何连接到MySQL服务器?

执行以下命令:

$ mysql -u root -p

输出示例:

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.49-3 (Debian)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

其中:

  • -u root:以管理员root用户身份登录。
  • -p:提示输入root用户密码。