linux mysql软件_「Linux」 - 常用软件安装-MySql
一、TIPS
1.5.6版本使用mysql_install_db安裝;5.7版本中被廢棄,使用--initialize,進行初始化安裝
2.初始化時,使用--initialize-insecure生成無密碼root賬戶
3.配置文件查找順序mysql --help | grep my.cnf結果如下/etc/my.cnf->/etc/mysql/my.cnf->/usr/local/mysql/etc/my.cnf->~/.my.cnf
二、安裝前準備
# 關閉SELinux
getenforce
setenforce 0
getenforce
# 關閉iptables
iptables -L
iptables -F
service iptables stop
# 關閉firewall(CentOS 7.x)
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
# 修改IO調用模式為deadline(默認為cfq模式)
cat /sys/block/vda/queue/scheduler
noop anticipatory deadline [cfq]
vim /etc/grub.conf
elevator=deadline
# swap分區設置查看(0表示積極使用物理內存,容易導致內存溢出;100表示積極使用swap分區,把內存數據搬到swap)
cat /proc/sys/vm/swappiness
60
sysctl -a | grep swap
vm.swappiness = 60
# swap分區設置
vim /etc/sysctl.conf
vm.swappiness = NEW_VALUE
三、二進制解壓安裝,京東云(CentOS 6.8、MySQL 5.7)
在各種測試環境安裝MySQL版本,已經疲了,總結下來二進制安裝包步驟雖然多,但是都可控,其他方式可能因為網絡不通,GLIBC版本不正確等各種問題。
二進制軟件包,官方GA版本已進把所有東西都配置完成,選擇Linux-Generic下載即可。
# 刪除mysql相關
rpm -qa | grep mysql
yum -y remove mysql-libs-5.1.73-7.el6.x86_64
# 下載二進制包
wget https://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
tar -vxzf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
# 增加mysql用戶
groupadd mysql
useradd mysql -g mysql
mkdir data
chown -R mysql:mysql /usr/local/mysql/
chmod -R mysql:mysql /usr/local/mysql/data/
chmod -R 755 /usr/local/mysql/
chmod -R 755 /usr/local/mysql/data/
# 新增my.cnf配置
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8
[mysql]
#自動補全
no-auto-rehash
default-character-set=utf8
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql/
# 測試庫,線上庫需要掛載到大硬盤
datadir = /usr/local/mysql/data
max_connections=2048
#max_allowed_packet = 128M
#open_files_limit = 65535
#sort_buffer_size = 2M
#join_buffer_size = 2M
#query_cache_size = 32M
#tmp_table_size = 96M
#max_heap_table_size = 96M
#key_buffer_size = 32M
#net_buffer_length = 8K
#read_buffer_size = 1M
#read_rnd_buffer_size = 16M
#thread_cache_size = 51
#back_log = 103
#table_open_cache = 64
pid-file = /usr/local/mysql/data/mysql.pid
log-error = /usr/local/mysql/data/error.log
#log-bin = /usr/local/mysql/data/mysql-bin
#sync_binlog = 1
#binlog_cache_size = 5M
#binlog_format = row
#max_binlog_cache_size = 128M
#max_binlog_size = 1024M
#expire_logs_days = 7
#slow_query_log = 1
#slow_query_log = /usr/local/mysql/data/slow.log
#long_query_time = 0.5
[mysqldump]
quick
max_allowed_packet = 32M
[mysqlhotcopy]
interactive-timeout
# init
/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql
# 啟動文件
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql stop
service mysql start
# 修改密碼
ln -s /usr/local/mysql/bin/mysql /usr/bin
grep "password" /usr/local/mysql/data/error.log --color
mysql -uroot -p
# 設置新密碼
mysql> SET PASSWORD = PASSWORD('NEW-PASSWORD');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> CREATE USER '_root'@'%' IDENTIFIED BY 'NEW-PASSWORD';
# 增加遠程用戶
mysql> GRANT ALL PRIVILEGES ON *.* TO '_root'@'%';
mysql> FLUSH PRIVILEGES;
四、yum安裝(Centos 7.4、MySQL 5.7)
對于和以上步驟相同的部分省略。
# 系統信息
cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
Server version: 5.7.22 MySQL Community Server (GPL)
# 停止mysql進程
pkill -9 mysqld
# 下載mysql源(注意版本與系統保持一致)
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
service mysqld restart
五、本地rpm安裝
# 下載rpm安裝包
wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.22-1.el6.x86_64.rpm-bundle.tar
tar -vxf mysql-5.7.22-1.el6.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-server-5.7.22-1.el6.x86_64.rpm --nodeps
rpm -ivh mysql-community-client-5.7.22-1.el6.x86_64.rpm --nodeps
rpm -ivh mysql-community-libs-5.7.22-1.el6.x86_64.rpm --nodeps
rpm -ivh mysql-community-libs-compat-5.7.22-1.el6.x86_64.rpm --nodeps
rpm -ivh mysql-community-common-5.7.22-1.el6.x86_64.rpm --nodeps
rpm -ivh mysql-community-devel-5.7.22-1.el6.x86_64.rpm
# init
service mysqld restart
Initializing MySQL database: /usr/sbin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory [FAILED]
# 解決libnuma.so.1失敗
yum install numactl.x86_64
已安裝:
numactl.x86_64 0:2.0.9-2.el6
# 進行安全設置
/usr/bin/mysql_secure_installation
總結
以上是生活随笔為你收集整理的linux mysql软件_「Linux」 - 常用软件安装-MySql的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 查询后怎么定位列_MySQL
- 下一篇: MySQL编程技巧_PHP与MySQL开