之前虽然也安装过多次mysql,但每次都会遇到各种小问题,这次记录下来,以备后查。
首先是下载与安装
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm # yum install mysql-community-server
安装过程中间会出现选择y/n的,直接输入y即可,如下:
[root@APP1 /]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm --2017-10-21 22:59:14-- http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm [following] --2017-10-21 22:59:14-- https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm [following] --2017-10-21 22:59:16-- https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 23.219.33.198 Connecting to repo.mysql.com (repo.mysql.com)|23.219.33.198|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6140 (6.0K) [application/x-redhat-package-manager] Saving to: 鈓ysql-community-release-el7-5.noarch.rpm? 100%[====================================================================================================>] 6,140 --.-K/s in 0s 2017-10-21 22:59:16 (761 MB/s) - 鈓ysql-community-release-el7-5.noarch.rpm?saved [6140/6140] [root@APP1 /]# rpm -ivh mysql-community-release-el7-5.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:mysql-community-release-el7-5 ################################# [100%] [root@APP1 /]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/7): base/7/x86_64/group_gz | 156 kB 00:00:00 (2/7): extras/7/x86_64/primary_db | 110 kB 00:00:00 (3/7): mysql-connectors-community/x86_64/primary_db | 16 kB 00:00:03 (4/7): mysql-tools-community/x86_64/primary_db | 35 kB 00:00:03 (5/7): updates/7/x86_64/primary_db | 2.9 MB 00:00:03 (6/7): base/7/x86_64/primary_db | 5.7 MB 00:00:08 (7/7): mysql56-community/x86_64/primary_db | 179 kB 00:00:23 Determining fastest mirrors * base: mirrors.btte.net * extras: mirrors.163.com * updates: mirrors.sohu.com Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.6.38-2.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.6.38-2.el7 for package: mysql-community-server-5.6.38-2.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.38-2.el7.x86_64 --> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.38-2.el7.x86_64 --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.6.38-2.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.38-2.el7.x86_64 ---> Package mysql-community-common.x86_64 0:5.6.38-2.el7 will be installed ---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed --> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64 --> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be obsoleted ---> Package mysql-community-libs.x86_64 0:5.6.38-2.el7 will be obsoleting ---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed --> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch --> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch --> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch --> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch --> Running transaction check ---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed --> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch --> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch ---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed --> Running transaction check ---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed ---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================== Package Arch Version Repository Size ============================================================================================================================================== Installing: mysql-community-libs x86_64 5.6.38-2.el7 mysql56-community 2.0 M replacing mariadb-libs.x86_64 1:5.5.35-3.el7 mysql-community-server x86_64 5.6.38-2.el7 mysql56-community 59 M Installing for dependencies: mysql-community-client x86_64 5.6.38-2.el7 mysql56-community 19 M mysql-community-common x86_64 5.6.38-2.el7 mysql56-community 257 k perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k perl-DBI x86_64 1.627-4.el7 base 802 k perl-IO-Compress noarch 2.061-2.el7 base 260 k perl-Net-Daemon noarch 0.48-5.el7 base 51 k perl-PlRPC noarch 0.2020-14.el7 base 36 k Transaction Summary ============================================================================================================================================== Install 2 Packages (+8 Dependent packages) Total download size: 82 M Is this ok [y/d/N]: y Downloading packages: warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.38-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Public key for mysql-community-common-5.6.38-2.el7.x86_64.rpm is not installed (1/10): mysql-community-common-5.6.38-2.el7.x86_64.rpm | 257 kB 00:00:32 mysql-community-libs-5.6.38-2. FAILED ] 28 kB/s | 10 MB 00:44:43 ETA http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-libs-5.6.38-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-libs-5.6.38-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') Trying other mirror. (2/10): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00 (3/10): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00 (4/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00 (5/10): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00 (6/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00 (7/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00 mysql-community-server-5.6.38- FAILED ] 120 kB/s | 15 MB 00:09:29 ETA http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.38-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.38-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') Trying other mirror. (8/10): mysql-community-client-5.6.38-2.el7.x86_64.rpm | 19 MB 00:03:31 (9/10): mysql-community-libs-5.6.38-2.el7.x86_64.rpm | 2.0 MB 00:00:04 (10/10): mysql-community-server-5.6.38-2.el7.x86_64.rpm | 59 MB 00:09:15 ---------------------------------------------------------------------------------------------------------------------------------------------- Total 109 kB/s | 82 MB 00:12:51 Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql-community-release-el7-5.noarch (installed) From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : mysql-community-common-5.6.38-2.el7.x86_64 1/11 Installing : mysql-community-libs-5.6.38-2.el7.x86_64 2/11 Installing : mysql-community-client-5.6.38-2.el7.x86_64 3/11 Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 4/11 Installing : perl-Net-Daemon-0.48-5.el7.noarch 5/11 Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/11 Installing : perl-IO-Compress-2.061-2.el7.noarch 7/11 Installing : perl-PlRPC-0.2020-14.el7.noarch 8/11 Installing : perl-DBI-1.627-4.el7.x86_64 9/11 Installing : mysql-community-server-5.6.38-2.el7.x86_64 10/11 Erasing : 1:mariadb-libs-5.5.35-3.el7.x86_64 11/11 Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/11 Verifying : perl-Net-Daemon-0.48-5.el7.noarch 2/11 Verifying : perl-PlRPC-0.2020-14.el7.noarch 3/11 Verifying : mysql-community-client-5.6.38-2.el7.x86_64 4/11 Verifying : mysql-community-server-5.6.38-2.el7.x86_64 5/11 Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 6/11 Verifying : mysql-community-common-5.6.38-2.el7.x86_64 7/11 Verifying : mysql-community-libs-5.6.38-2.el7.x86_64 8/11 Verifying : perl-DBI-1.627-4.el7.x86_64 9/11 Verifying : perl-IO-Compress-2.061-2.el7.noarch 10/11 Verifying : 1:mariadb-libs-5.5.35-3.el7.x86_64 11/11 Installed: mysql-community-libs.x86_64 0:5.6.38-2.el7 mysql-community-server.x86_64 0:5.6.38-2.el7 Dependency Installed: mysql-community-client.x86_64 0:5.6.38-2.el7 mysql-community-common.x86_64 0:5.6.38-2.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Replaced: mariadb-libs.x86_64 1:5.5.35-3.el7 Complete! You have new mail in /var/spool/mail/root
安装成功后重启mysql服务
# service mysqld restart
初次安装mysql,root账户没有密码。
# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.38 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) mysql>
设置密码
mysql> set password for 'root'@'localhost'=password('password'); Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
配置编码格式
mysql> default-character-set =utf8
->
设置允许远程连接
mysql> grant all privileges on *.* to root@'%'identified by 'password'; Query OK, 0 rows affected (0.00 sec) mysql>
如果允许root账号远程连接要对系统数据库的root账户设置远程访问的密码,与本地的root访问密码并不冲突。
1 grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; #123456为你需要设置的密码