centos7 安裝mysql

安裝環境或方式

環境: centos7_64 安裝方式:官網下載安裝mysql-server ps:mysql安裝其實不難,可是並無把步驟記下來,因此我把安裝的步驟整理出來方便之後使用html

安裝mysql

順序執行下列語句mysql

[root@db01 mysql]# cd /usr/local/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

配置mysql

  1. 配置編碼格式 /etc/my.cnf 最後面添加 default-character-set =utf8 default-character-set =utf8
  2. 設置密碼
mysql> set password for 'root'@'localhost' =password('123456');
Query OK, 0 rows affected (0.01 sec)
  1. 新建用戶
mysql> create user 'hdfs'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
  1. 表的全部權限賦值給位於全部IP地址的root用戶
mysql> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
  1. 刷新修改
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

安裝過程日誌

[root@db01 mysql]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
--2019-02-13 10:04:20--  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... dRead error (Connection reset by peer) in headers.
Retrying.

--2019-02-13 10:04:31--  (try: 2)  http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
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]
--2019-02-13 10:04:34--  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]
--2019-02-13 10:04:36--  https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 173.223.96.113
Connecting to repo.mysql.com (repo.mysql.com)|173.223.96.113|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql-community-release-el7-5.noarch.rpm’

100%[==========================================================================>] 6,140       --.-K/s   in 0s

2019-02-13 10:04:38 (34.2 MB/s) - ‘mysql-community-release-el7-5.noarch.rpm’ saved [6140/6140]
[root@db01 mysql]# ll
total 8
-rw-r--r--. 1 root root 6140 Nov 12  2015 mysql-community-release-el7-5.noarch.rpm
[root@db01 mysql]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]
[root@db01 mysql]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 68490.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  36 M RSS (860 MB VSZ)
    Started: Wed Feb 13 10:04:58 2019 - 00:07 ago
    State  : Running, pid: 68490
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  44 M RSS (868 MB VSZ)
    Started: Wed Feb 13 10:04:58 2019 - 00:09 ago
    State  : Sleeping, pid: 68490
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  47 M RSS (872 MB VSZ)
    Started: Wed Feb 13 10:04:58 2019 - 00:11 ago
    State  : Sleeping, pid: 68490
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  47 M RSS (872 MB VSZ)
    Started: Wed Feb 13 10:04:58 2019 - 00:13 ago
    State  : Sleeping, pid: 68490
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.43-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.43-2.el7 for package: mysql-community-server-5.6.43-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.43-2.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.43-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.43-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.43-2.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be obsoleted
---> Package mysql-community-libs.x86_64 0:5.6.43-2.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
 Package                            Arch               Version                  Repository                     Size
====================================================================================================================
Installing:
 mysql-community-libs               x86_64             5.6.43-2.el7             mysql56-community             2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 mysql-community-server             x86_64             5.6.43-2.el7             mysql56-community              59 M
Installing for dependencies:
 mysql-community-client             x86_64             5.6.43-2.el7             mysql56-community              20 M
 mysql-community-common             x86_64             5.6.43-2.el7             mysql56-community             257 k

Transaction Summary
====================================================================================================================
Install  2 Packages (+2 Dependent packages)

Total download size: 81 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.43-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.6.43-2.el7.x86_64.rpm is not installed
(1/4): mysql-community-common-5.6.43-2.el7.x86_64.rpm                                        | 257 kB  00:00:03
(2/4): mysql-community-libs-5.6.43-2.el7.x86_64.rpm                                          | 2.0 MB  00:00:40
(3/4): mysql-community-client-5.6.43-2.el7.x86_64.rpm                                        |  20 MB  00:06:53
(4/4): mysql-community-server-5.6.43-2.el7.x86_64.rpm                                        |  59 MB  00:27:40
--------------------------------------------------------------------------------------------------------------------
Total                                                                                49 kB/s |  81 MB  00:28:25
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.43-2.el7.x86_64                                                       1/5
  Installing : mysql-community-libs-5.6.43-2.el7.x86_64                                                         2/5
  Installing : mysql-community-client-5.6.43-2.el7.x86_64                                                       3/5
  Installing : mysql-community-server-5.6.43-2.el7.x86_64                                                       4/5
  Erasing    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                             5/5
  Verifying  : mysql-community-server-5.6.43-2.el7.x86_64                                                       1/5
  Verifying  : mysql-community-common-5.6.43-2.el7.x86_64                                                       2/5
  Verifying  : mysql-community-libs-5.6.43-2.el7.x86_64                                                         3/5
  Verifying  : mysql-community-client-5.6.43-2.el7.x86_64                                                       4/5
  Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                             5/5

Installed:
  mysql-community-libs.x86_64 0:5.6.43-2.el7              mysql-community-server.x86_64 0:5.6.43-2.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.43-2.el7             mysql-community-common.x86_64 0:5.6.43-2.el7

Replaced:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5

Complete!
[root@db01 mysql]# ll
total 8
-rw-r--r--. 1 root root 6140 Nov 12  2015 mysql-community-release-el7-5.noarch.rpm
[root@db01 mysql]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
s[root@db01 mysql]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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>

可能遇到的問題

鏈接mysql報錯

在退出來從新鏈接mysql的時候報錯,不管是用root仍是新建的用戶hdfs,看起來像是密碼沒有生效sql

[root@db01 hdfs]# mysql -uhdfs -p'123456'
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'hdfs'@'localhost' (using password: YES)

經過查閱資料,發現這個錯誤通常是由密碼錯誤引發,解決的辦法天然就是重置密碼。在這以前我也重置過密碼,至於爲何沒生效搞懂,應該是方法不對,因此在規範了重置密碼後這個問題就解決了 如今連mysql都鏈接不上,更談不上重置密碼之類的操做了(也許有方法直接重置,可是我母雞啊) 那麼就要經過一下步驟來重置密碼了數據庫

  1. MySQL的密碼認證過程
[root@db01 mysql]#  vim /etc/my.cnf

在文件中 [mysqld] 下添加 skip-grant-tables #添加跳過密碼驗證的語句vim

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
skip-grant-tables  #添加跳過密碼驗證的語句
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set =utf8

wq 保存文檔並退出 接下來 service mysqld restart #重啓mysql 有些用 service mysql restart mysql #免密碼登錄 use mysql; 切換數據庫 update user set password=password("123456") where user="root"; #修改密碼 flush privileges; #刷新修改 quit ;#退出 操做以下centos

[root@db01 mysql]# service mysqld restart 
Redirecting to /bin/systemctl restart mysqld.service
[root@db01 mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password("123456") where user="root";
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5  Changed: 5  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

接下來my.cnf,去掉或者註釋掉剛纔添加的內容,保存退出oracle

[mysqld]
# skip-grant-tables  #添加跳過密碼驗證的語句

從新啓動mysqlapp

[root@db01 mysql]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@db01 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> exit
Bye

登錄輸入用戶密碼登錄mysql成功socket

本文爲本人平常工做整理總結,轉載請註明出處!!!ide

相關文章
相關標籤/搜索