Centos7.4下安裝mysql-5.6.41

Centos7.4下安裝mysql-5.6.41二進制包node

一、下載
mkdir /data/sql
cd /data/sqlmysql

wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41-linux-glibc2.12-x86_64.tar.gzlinux

二、查詢是否有安裝過mysql
rpm -qa | grep mysql sql

如有的話,卸載低版本的MySQL
rpm -e --nodeps mysql* 數據庫

卸載MariaDB
查看當前安裝的mariadb包:# rpm -qa | grep mariadb
都卸載掉:# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64socket

三、重命名MySQL5.6.41名稱
mv mysql-5.6.41-linux-glibc2.12-x86_64 /data/mysqlide

由於我想mysql放在一個掛載盤下/data (屬於掛載盤的目錄)
可是basedir和datadir仍是用/usr/local/mysql
就作個軟鏈接rest

ln -s /data/mysql /usr/local/cdn

四、建立MySQL用戶及用戶組server

groupadd mysql
useradd -r -g mysql mysql

chown -R mysql.mysql /data/mysql

五、安裝MySQL
先安裝一些庫文件
yum –y install perl perl-devel
yum -y install autoconf
yum install libaio* -y

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#####
問題1:如有提示:FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:

解決方法 :安裝autoconf庫
命令:yum -y install autoconf

#####
問題2:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
緣由:缺乏libaio庫文件
解決方法:yum install libaio* -y

六、/etc/profile文件裏添加下面MySQL環境變量
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

輸入命令使其生效
source /etc/profile

七、複製my.cnf
cp /data/mysql/support-files/my-default.cnf /etc/my.cnf

添加一下內容:
具體參數根據你實際狀況來, 本身調優

###############
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

socket=/usr/local/mysql/mysql.sock

port=3306
user=mysql

max_allowed_packet = 1024M
net_read_timeout = 60
net_retry_count = 10
net_write_timeout = 60
connect_timeout=30

max_connections=2000
skip-name-resolve=1

innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M

#slow_query_log = ON
#slow_query_log_file = /usr/local/mysql/data/slow.log
#long_query_time = 1

character_set_server = utf8

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
socket=/usr/local/mysql/mysql.sock

[client]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
max_allowed_packet=1024M

#################

八、初始化MySQL服務
cd /usr/local/mysql/
[root@iZuf6g67k0g2w9urauj6npZ mysql]# mysqld_safe
180930 12:00:53 mysqld_safe Logging to '/var/log/mysqld.log'.
180930 12:00:53 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
180930 12:01:13 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

九、設置開機啓動服務

cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld

chkconfig --add mysqld
chkconfig mysqld on

開機啓動服務
chkconfig --add mysqld
chkconfig mysqld on

十、啓動MySQL服務
/etc/init.d/mysqld start

問題: [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
解決方法由於目錄沒有賦權MySQL致使,解決從新執行就能夠
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

若用了/ect/my.cnf來控制參數設置,那/data/mysql/下的my.cnf須要刪除掉,否則配置會優先/data/my.cnf

問題2:[ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 768 pages (rounded down to MB) than specified in the .cnf file: initial 12800 pages, max 0 (relevant if non-zero) pages!
解決方法:#cd /data/mysql/data
#rm -rf /data/mysql/data/ib*
主要刪除:ibdata一、ib_logfile0、ib_logfile1

重啓服務
/etc/init.d/mysqld restart

十一、修改密碼及賦權

方法1: 用SET PASSWORD命令
首先登陸MySQL。
格式:mysql> set password for 用戶名@localhost = password('新密碼');
例子:mysql> set password for root@localhost = password('123');

方法2:用mysqladmin
格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼
例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接編輯user表
首先登陸MySQL。
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;

十二、賦權
#指定IP、指定帳號、密碼訪問數據庫
mysql> GRANT ALL PRIVILEGES ON . TO [username]@"[ip]" IDENTIFIED BY "[password]";
 
#指定IP、指定帳號、密碼訪問數據庫-查詢權限
mysql> grant select on 數據庫.* to 用戶@IP identified by '密碼';

#刷新mysql> flush privileges;

相關文章
相關標籤/搜索