Linux MySql5.6.38安裝過程


1.下載mysql安裝包mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz

2.用xftp工具將其上傳到Linux服務器上的soft文件夾,沒有的話先創建

[root@master ~]# cd /
[root@master /]# ls
bin dev home lib64 media opt root selinux sys usr
boot etc lib lost+found mnt proc sbin srv tmp var
[root@master /]# mkdir soft

3.解壓mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz

[root@master soft]# tar ‐zxvf mysql‐5.6.38‐linux‐glibc2.12‐x86_64.tar.gz

4.刪除mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz並將解壓的文件夾重命名為mysql

[root@master soft]# ls
mysql‐5.6.38‐linux‐glibc2.12‐x86_64 mysql‐5.6.38‐linux‐glibc2.12‐x86_64.tar.gz
[root@master soft]# rm ‐rf mysql‐5.6.38‐linux‐glibc2.12‐x86_64.tar.gz
[root@master soft]# mv mysql‐5.6.38‐linux‐glibc2.12‐x86_64/ mysql

5.查看之前系統是否安裝過mysql

[root@master soft]# rpm ‐qa|grep mysql
mysql‐libs‐5.1.735.el6_6.x86_64

6.卸載之前安裝過的mysql

[root@master soft]# rpm ‐e ‐‐nodeps mysql‐libs‐5.1.735.el6_6.x86_64
[root@master soft]# rpm ‐qa|grep mysql
[root@master soft]#

7.查看系統之前是否有mysql用戶

[root@master soft]# groups mysql
groups: mysql:無此用戶

8.創建mysql用戶組及用戶

[root@master soft]# groupadd mysql
[root@master soft]# useradd ‐r ‐g mysql mysql

9.將解壓的mysql文件夾移動到/usr/local目錄下

[root@master soft]# mv mysql/ /usr/local/

10.進入/usr/local/文件夾並修改mysql文件夾用戶組及用戶為mysql

[root@master soft]# cd /usr/local/
[root@master local]# chown ‐R mysql:mysql mysql
[root@master local]# ll
總用量 44
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 bin
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 etc
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 games
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 include
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 lib
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 lib64
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 libexec
drwxr‐xr‐x. 13 mysql mysql 4096 1月 16 04:04 mysql
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 sbin
drwxr‐xr‐x. 5 root root 4096 1月 16 02:15 share
drwxr‐xr‐x. 2 root root 4096 9月 23 2011 src
[root@master local]#

11.修改/etc/hosts文件夾將IP和主機名添加進去

[root@master scripts]# vi /etc/hosts
192.168.1.110 master
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

12.進入mysql/scripts/文件夾,進行安裝

[root@master scripts]# ./mysql_install_db ‐‐basedir=/usr/local/mysql ‐‐
datadir=/usr/local/mysql/data ‐‐user=mysql ‐‐explicit_defaults_for_timestamp
 1 Installing MySQL system tables...20180116 04:21:19 0 [Note] Ignoring ‐‐secure‐file‐priv value
 2 as server is running with ‐‐bootstrap.
 3 20180116 04:21:19 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.38) starting as process
 4 1996 ...
 5 20180116 04:21:19 1996 [Note] InnoDB: Using atomics to ref count buffer pool pages
 6 20180116 04:21:19 1996 [Note] InnoDB: The InnoDB memory heap is disabled
 7 20180116 04:21:19 1996 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
 8 20180116 04:21:19 1996 [Note] InnoDB: Memory barrier is not used
 9 20180116 04:21:19 1996 [Note] InnoDB: Compressed tables use zlib 1.2.3
10 20180116 04:21:19 1996 [Note] InnoDB: Using Linux native AIO
11 20180116 04:21:19 1996 [Note] InnoDB: Using CPU crc32 instructions
12 20180116 04:21:19 1996 [Note] InnoDB: Initializing buffer pool, size = 128.0M
13 20180116 04:21:19 1996 [Note] InnoDB: Completed initialization of buffer pool
14 20180116 04:21:19 1996 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a
15 new database to be created!
16 20180116 04:21:19 1996 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
17 20180116 04:21:19 1996 [Note] InnoDB: Database physically writes the file full: wait...
18 20180116 04:21:19 1996 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
19 20180116 04:21:20 1996 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
20 20180116 04:21:20 1996 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
21 20180116 04:21:20 1996 [Warning] InnoDB: New log files created, LSN=45781
22 20180116 04:21:20 1996 [Note] InnoDB: Doublewrite buffer not found: creating new
23 20180116 04:21:20 1996 [Note] InnoDB: Doublewrite buffer created
24 20180116 04:21:20 1996 [Note] InnoDB: 128 rollback segment(s) are active.
25 20180116 04:21:20 1996 [Warning] InnoDB: Creating foreign key constraint system tables.
26 20180116 04:21:20 1996 [Note] InnoDB: Foreign key constraint system tables created
27 20180116 04:21:20 1996 [Note] InnoDB: Creating tablespace and datafile system tables.
28 20180116 04:21:20 1996 [Note] InnoDB: Tablespace and datafile system tables created.
29 20180116 04:21:20 1996 [Note] InnoDB: Waiting for purge to start
30 20180116 04:21:20 1996 [Note] InnoDB: 5.6.38 started; log sequence number 0
31 20180116 04:21:21 1996 [Note] Binlog end
32 20180116 04:21:21 1996 [Note] InnoDB: FTS optimize thread exiting.
33 20180116 04:21:21 1996 [Note] InnoDB: Starting shutdown...
34 20180116 04:21:22 1996 [Note] InnoDB: Shutdown completed; log sequence number 1625977
35 OK
36 Filling help tables...20180116 04:21:22 0 [Note] Ignoring ‐‐secure‐file‐priv value as server
37 is running with ‐‐bootstrap.
38 20180116 04:21:22 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.38) starting as process
39 2018 ...
40 20180116 04:21:22 2018 [Note] InnoDB: Using atomics to ref count buffer pool pages
41 20180116 04:21:22 2018 [Note] InnoDB: The InnoDB memory heap is disabled
42 20180116 04:21:22 2018 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
43 20180116 04:21:22 2018 [Note] InnoDB: Memory barrier is not used
44 20180116 04:21:22 2018 [Note] InnoDB: Compressed tables use zlib 1.2.3
45 20180116 04:21:22 2018 [Note] InnoDB: Using Linux native AIO
46 20180116 04:21:22 2018 [Note] InnoDB: Using CPU crc32 instructions
47 20180116 04:21:22 2018 [Note] InnoDB: Initializing buffer pool, size = 128.0M
48 20180116 04:21:22 2018 [Note] InnoDB: Completed initialization of buffer pool
49 20180116 04:21:22 2018 [Note] InnoDB: Highest supported file format is Barracuda.
50 20180116 04:21:22 2018 [Note] InnoDB: 128 rollback segment(s) are active.
51 20180116 04:21:22 2018 [Note] InnoDB: Waiting for purge to start
52 20180116 04:21:22 2018 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
53 20180116 04:21:22 2018 [Note] Binlog end
54 20180116 04:21:22 2018 [Note] InnoDB: FTS optimize thread exiting.
55 20180116 04:21:22 2018 [Note] InnoDB: Starting shutdown...
56 20180116 04:21:24 2018 [Note] InnoDB: Shutdown completed; log sequence number 1625987
57 OK
58 To start mysqld at boot time you have to copy
59 support‐files/mysql.server to the right place for your system
60 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
61 To do so, start the server, then issue the following commands:
62 /usr/local/mysql/bin/mysqladmin ‐u root password 'new‐password'
63 /usr/local/mysql/bin/mysqladmin ‐u root ‐h master password 'new‐password'
64 Alternatively you can run:
65 /usr/local/mysql/bin/mysql_secure_installation
66 which will also give you the option of removing the test
67 databases and anonymous user created by default. This is
68 strongly recommended for production servers.
69 See the manual for more instructions.
70 You can start the MySQL daemon with:
71 cd . ; /usr/local/mysql/bin/mysqld_safe &
72 You can test the MySQL daemon with mysql‐test‐run.pl
73 cd mysql‐test ; perl mysql‐test‐run.pl
74 Please report any problems at http://bugs.mysql.com/
75 The latest information about MySQL is available on the web at
76 http://www.mysql.com
77 Support MySQL by buying support/licenses at http://shop.mysql.com
78 New default config file was created as /usr/local/mysql/my.cnf and
79 will be used by default by the server when you start it.
80 You may edit this file to change server settings
View Code

可能出現的錯誤

1、數據初始化‐主機名解析錯誤
系統‐Red Hat Enterprise Linux Server release 6.6
軟件‐源碼安裝mysql‐5.6.27.tar.gz
環境‐Linux rhel6.myexample.com 2.6.32504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64
x86_64 x86_64 GNU/Linux
報錯:WARNING
[root@rhel6 mysql]# scripts/mysql_install_db ‐‐user=mysql
WARNING: The host 'rhel6.myexample.com' could not be looked up with ./bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
原因:主機名解析錯誤。
解決:hosts文件中添加如下內容,ok!
[root@rhel6 mysql]# vi /etc/hosts
192.168.56.20 rhel6.myexample.com
總結:
因為lib庫不是很兼容當前MySQL版本。在主機名解析不起作用的情況下,會引起MySQL守護進程、mysqld工作異常,因
此在MySQL中授權時需要使用IP地址,而不能使用主機名。
(不解決該問題,依然可以正確執行scripts/mysql_install_db數據庫初始化腳本。)
2、數據初始化‐時間戳問題
系統‐Red Hat Enterprise Linux Server release 6.6
軟件‐源碼安裝mysql‐5.6.27.tar.gz
環境‐Linux rhel6.myexample.com 2.6.32504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64
x86_64 x86_64 GNU/Linux
報錯:Warning
[root@rhel6 mysql]# scripts/mysql_install_db ‐‐user=mysql
Installing MySQL system tables...20151104 07:46:37 0 [Warning] TIMESTAMP with implicit DEFAULT
value is deprecated. Please use ‐‐explicit_defaults_for_timestamp server option (see
documentation for more details).
20151104 07:46:37 0 [Note] ./bin/mysqld (mysqld 5.6.27) starting as process 2867 ...
原因:機器的系統時間與TIMESTAMP時間戳不匹配。
解決:執行mysql_install_db數據初始化腳本時添加explicit_defaults_for_timestamp選項。
[root@rhel6 mysql]# scripts/mysql_install_db ‐‐user=mysql ‐‐explicit_defaults_for_timestamp
3、數據初始化‐重復安裝引起多個配置文件,默認配置文件
系統‐Red Hat Enterprise Linux Server release 6.6
軟件‐源碼安裝mysql‐5.6.27.tar.gz
環境‐Linux rhel6.myexample.com 2.6.32504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64
x86_64 x86_64 GNU/Linux
報錯:Warning
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used ‐‐defaults‐file)
and when you later start the server.
The new default config file was created as ./my‐new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
‐‐defaults‐file argument to mysqld_safe when starting the server
原因:
Warning1是因為重復安裝,導致在安裝目錄下已經存在my.cnf文件。
Warning2是指默認的my.cnf配置文件在/etc/目錄下。
啟動Mysql server時,可指定‐‐default‐file=/path/my.cnf參數來啟動mysql服務。

13.返回上一級mysql目錄,修改data文件及用戶組及用戶為mysql

[root@master scripts]# cd ..
[root@master mysql]# chown ‐R mysql:mysql data

14.修改mysql密碼,之前安裝時已經提示如何修改

/usr/local/mysql/bin/mysqladmin ‐u root password 'new‐password'
/usr/local/mysql/bin/mysqladmin ‐u root ‐h master password 'new‐password'
[root@master bin]# ./mysqladmin ‐u root password 'root'

有可能會出現以下錯誤

[root@master bin]# ./mysqladmin ‐u root password 'root'
./mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[root@master bin]#

因為這時還沒有啟動mysql,這算是一個坑。

15.啟動mysql,進入mysql/support-files文件夾執行命令

[root@master mysql]# cd support‐files/
[root@master support‐files]# ls
binary‐configure magic my‐default.cnf mysqld_multi.server mysql‐log‐rotate mysql.server
[root@master support‐files]# ./mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/master.err'.
SUCCESS!
[root@master support‐files]#

16.在重新執行命令修改密碼

[root@master bin]# ./mysqladmin ‐u root password 'root'
Warning: Using a password on the command line interface can be insecure.
[root@master bin]#

17.登錄mysql

[root@master bin]# ./mysql ‐uroot ‐p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
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>

18.將其他用戶的密碼也修改為root

update mysql.user set password=password('root') where user='root'; flush privileges;
mysql> update mysql.user set password=password('root') where user='root'; flush privileges;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
mysql>

19.在Windows上遠程連接mysql,此時端口不同,關閉Linux上的防火牆

[root@master bin]# service iptables stop
iptables:將鏈設置為政策 ACCEPT:filter [確定]
iptables:清除防火牆規則: [確定]
iptables:正在卸載模塊: [確定]
[root@master bin]#

此時在Windows上用cmd窗口Telnet Linux服務器3306端口報錯

D•Host '192.168.1.1' is not allowed to connect to
遺失對主機的連接。
C:\Users\Administrator>telnet 192.168.1.110 3306

為解決這一問題,需要本地登陸MySQL后執行如下命令

mysql> grant all privileges on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>

執行之后即可連接成功

 

 

 20.將mysql加入services服務

[root@master mysql]# cp support‐files/mysql.server /etc/init.d/mysqld
[root@master mysql]# chkconfig ‐‐add mysqld
[root@master mysql]# chkconfig mysqld on
[root@master mysql]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
[root@master mysql]#

查看狀態

[root@master mysql]# service mysqld status
SUCCESS! MySQL running (21838)
[root@master mysql]#

21.配置my.cnf

[root@master mysql]# vi my.cnf
[mysqld]
# 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
default‐character‐set=utf8
lower_case_table_names=1
max_allowed_packet=100M
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# 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

 配置好之后充氣mysql服務

[root@master data]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file
(/usr/local/mysql/data/master.pid).

此時報錯,查看/usr/local/mysql/data/master.err文件發現報錯內容

20180116 04:49:52 22747 [ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'defaultcharacter‐
set=utf8'
20180116 04:49:52 22747 [ERROR] Aborting

my.cnf字符集設置問題,重新設置為character_set_server=utf8

 重新啟動解決

[root@master mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@master mysql]#

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM