mysql在线安装
1.下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2.使用yum安装MySQL
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
出现如下图就表示正常
3.启动MySQL
systemctl start mysqld.service
4.查看mysql状态
ystemctl status mysqld.service
5.查看mysql初始密码
grep "password" /var/log/mysqld.log
6登录mysql
mysql -uroot -p # 回车后会提示输入密码
修改mysql的root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
FLUSH PRIVILEGES;
来源:MySQL安装之yum安装 - Brian_Zhu - 博客园
yum安装指定版本mysql
1、下载mysql rpm包
cd /usr/local/src
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2、安装下载的rpm包
yum localinstall mysql80-community-release-el7-3.noarch.rpm
或
sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm
3、查看yum存储库中的mysql版本,默认最新的enabled,需要改成需要的版本
yum repolist all | grep mysql
4、修改为需要的版本,机禁用yum存储库中mysql不需要的版本和开启需要的版本
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
或
手动编辑/etc/yum.repos.d/mysql-community.repo 文件来选择,把默认版本的enabled=1改为0,需要版本的enabled=1
5、安装mysql
yum install mysql-community-server
mysql离线安装
1、下载安装包 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
下载地址https://dev.mysql.com/downloads/mysql/5.6.html
历史版本下载:DOWNLOADS---->Archives---->MySQL Community Server---->Product Version----->Operating System(选择Linux- Generic) ----->带glibc的就是二进制包
下载这个版本:
2、卸载系统自带的Mariadb
rpm -qa|grep mariadb //查询出已安装的mariadb
rpm -e --nodeps 文件名 //卸载 , 文件名为使用rpm -qa|grep mariadb 命令查出的所有文件
3、删除etc目录下的my.cnf文件
rm /etc/my.cnf
4、 执行以下命令来创建mysql用户组
groupadd mysql
5、执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组
useradd -g mysql mysql
6、将下载的二进制压缩包放到/usr/local/目录下。
7、解压安装包
tar -zxvfmysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
8、将解压好的文件夹重命名为mysql
9、在etc下新建配置文件my.cnf,并在该文件内添加以下代码:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/mysql_data
# 允许最大连接数
max_connections=10240
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
线上my.conf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/mysql_data
# 允许最大连接数
max_connections=10240
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
log_error = /data/mysql/log/error.log
slow_query_log_file = /data/mysql/log/slow.log
open_files_limit = 102400
back_log = 2048
max_connections = 4096
max_connect_errors = 40960
table_cache = 1024
external-locking = FALSE
max_allowed_packet = 1024M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 600
thread_concurrency = 16
query_cache_size = 64M
query_cache_limit = 8M
query_cache_type = 2
query_cache_min_res_unit = 4k
#default_table_type = InnoDB
thread_stack = 192K
tmp_table_size = 2048M
max_heap_table_size = 512M
#log-bin = /data/mysql/mysql-bin
#relay-log=mysql02-relay-bin
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout =240
wait_timeout = 240
skip-name-resolve
server-id = 20
innodb_additional_mem_pool_size = 32M
#innodb_buffer_pool_size = 30G
#innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 4
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table
[root@bj4bo75at8giw0 mysql]# ^C
[root@bj4bo75at8giw0 mysql]# ^C
(reverse-i-search)`mysql': ./bin/^Csql -h127.0.0.1 -p
[root@bj4bo75at8giw0 mysql]# mysql -h127.0.0.1 -p
-bash: mysql: command not found
[root@bj4bo75at8giw0 mysql]# cat /etc/my.conf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/data/mysql/data
# 允许最大连接数
max_connections=10240
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
log_error = /data/mysql/log/error.log
slow_query_log_file = /data/mysql/log/slow.log
open_files_limit = 102400
back_log = 2048
max_connections = 4096
max_connect_errors = 40960
table_cache = 1024
external-locking = FALSE
max_allowed_packet = 1024M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 600
thread_concurrency = 16
query_cache_size = 64M
query_cache_limit = 8M
query_cache_type = 2
query_cache_min_res_unit = 4k
#default_table_type = InnoDB
thread_stack = 192K
tmp_table_size = 2048M
max_heap_table_size = 512M
#log-bin = /data/mysql/mysql-bin
#relay-log=mysql02-relay-bin
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout =240
wait_timeout = 240
skip-name-resolve
server-id = 20
innodb_additional_mem_pool_size = 32M
#innodb_buffer_pool_size = 30G
#innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 4
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table
10、创建步骤9中用到的目录并将其用户设置为mysql
mkdir /var/lib/mysql
mkdir /var/lib/mysql/mysql
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /mysql_data
11、安装数据库
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql
centos 7安装mysql报错-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
貌似提示注释器错误,没有/usr/bin/perl文件或者档案,解决办法(安装perl跟perl-devel即可):
执行 yum -y install perl perl-devel
后在初始化数据库即可。
bin/mysql_install_db
FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:
Data::Dumperyum install -y perl-Data-Dumper 即可。。
如果出现libaio相关错误,执行yum -y libaio*
如果需要离线安装这些依赖,需要先在可以使用yum的环境中将依赖包下载好
yum -y install yum-utils
sudo repotrack deplist perl-Data-Dumper -p perl_all
sudo repotrack libaio* -p libaio
然后将依赖包复制到离线环境
cd perl_all
rpm -ivh *.rpm --nodeps --force
cd ../perl_all libaio
rpm -ivh *.rpm --nodeps --force
12、启动msyql
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chown +x /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld restart