02 Mysql5.6 数据库安装
程序员文章站
2022-03-03 14:41:30
...
CentOS7 通过YUM安装MySQL5.7
https://www.cnblogs.com/jorzy/p/8455519.html
安装Perl
yum install -y perl-Module-Install.noarch
使用root创建用户组、用户
[[email protected] ~]# groupadd mall
[[email protected] ~]# useradd mall -g mall
[[email protected] ~]# su mall
[[email protected] 1.6.0_45]# passwd mall
Changing password for user mall.
New password: ******
切换到新建的用户根目录下(/home/mall/)
[[email protected] ~]# cd ~
下载Mysql安装包
wget mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz
解压缩安装包
[[email protected] ~]$ tar vxf mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz
.....
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/insert_select-binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/ctype_ucs_binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/binlog_mysqlbinlog_row.inc
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/implicit.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/blackhole.test
更新目录名称
[[email protected] ~]$ mv mysql-5.6.22-linux-glibc2.5-x86_64 mysql
[[email protected] ~]$ ll
total 304364
drwxrwxr-x. 13 mall mall 4096 Sep 18 20:06 mysql
上传配置文件、启动命令到conf目录***意,这里使用的是root用户)
[[email protected] mysql]$ mkdir conf
[[email protected] mysql]# pwd
/home/mall/mysql
[[email protected] mysql]# chown -R mall:mall conf
[[email protected] mysql]# cd conf/
[[email protected] conf]# ll
total 8
-rw-r--r--. 1 mall mall 2943 Sep 18 20:09 my.cnf
-rw-r--r--. 1 mall mall 1017 Sep 18 20:09 startMysqld.sh
[[email protected] conf]# chmod +x startMysqld.sh
执行Mysql初始化脚本
[[email protected] mysql]$ ./scripts/mysql_install_db --user=mall --basedir=/home/mall/mysql/ --datadir=/home/mall/mysql/data/
Installing MySQL system tables...2016-09-18 20:13:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-18 20:13:07 18308 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
2016-09-18 20:13:07 18308 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
........
2016-09-18 20:13:11 18330 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/home/mall/mysql//bin/mysqladmin -u root password 'new-password'
/home/mall/mysql//bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
........
初始化Mysql root用户的初始密码
/home/mall/mysql/bin/mysqladmin -u root -h 127.0.0.1 -P 3306 password '123456'
注意:用于生产环境的初始密码必须设置足够复杂,这里仅用于测试。
启动数据库
[[email protected] mysql]$ ./conf/startMysqld.sh
cat: /home/mall/mysql/log/mysql.pid: No such file or directory
1、正在停止正在运行的端口为3306的Mysql实例,PID:,请等待......
./conf/startMysqld.sh: line 18: [: -ne: unary operator expected
2、正在启动端口为3306的Mysql实例,请等待......
2016-09-18 20:17:16 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2016-09-18 20:17:16 0 [Warning] Ignoring user change to 'mall' because the user was set to 'umeng' earlier on the command line
2016-09-18 20:17:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-18 20:17:16 18374 [Warning] One can only use the --user switch if running as root
3、新启动的Mysql实例,PID:18374
测试数据库
登录数据库
[[email protected] mysql]$ /home/mall/mysql/bin/mysql -u root -h 127.0.0.1 -P 3306 -prootpwd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.04 sec)
设置远程登录
GRANT ALL PRIVILEGES ON *.* TO [email protected]'%' identified by '123456';
flush privileges;
注意:这两条语句是需要先登录数据库才能执行,[123456]密码需要替换为root的密码。
修改Linux字符集##
步骤1:
修改i18n文件
vi /etc/sysconf/i18n
将默认LANG修改为
LANG="zh_CN.UTF-8"
步骤2:
切换为mysql启动用户(root、mall)
su root
注意:两个用户都需要设置
编辑.bash_profile文件
vi ~/.bash_profile
在文件的最后增加两行
export LANG=zh_CN.UTF-8
export LANG
退出编辑,执行
source ~/.bash_profile
startMysqld.sh脚本源码
#! /bin/bash
port=3306
user=mall
basedir=${HOME}/mysql
mkdir -p ${basedir}/{tmp,data,log}
while getopts 'p:u:' opt
do
case $opt in
p)port=$OPTARG;;
u)user=$OPTARG;;
esac
done
pid=`cat ${basedir}/log/mysql.pid`
echo "1、正在停止正在运行的端口为$port的Mysql实例,PID:$pid,请等待......"
if [ $pid -ne 0 ]
then
kill $pid
sleep 2
fi
echo "2、正在启动端口为$port的Mysql实例,请等待......"
echo 0 > ${basedir}/log/mysql.pid
${basedir}/bin/mysqld --defaults-file=${basedir}/conf/my.cnf --basedir=${basedir} \
--datadir=${basedir}/data --plugin-dir=${basedir}/lib/plugin --log-error=${basedir}/log/mysqld.err \
--open-files-limit=102400 --pid-file=${basedir}/log/mysql.pid --socket=${basedir}/tmp/mysql.sock \
--user=${user} --port=${port}&
sleep 5
pid=`cat ${basedir}/log/mysql.pid`
if [ $pid -eq 0 ]
then
echo "3、检查新启动的Mysql实例PID失败,请手动检查进程是否启动完成!"
else
echo "3、新启动的Mysql实例,PID:$pid"
fi
my.cnf脚本源码
[client]
port = 3307
socket =
socket = /home/mall/mysql/tmp/mysql.sock
default-character-set = utf8
[mysqld]
character-set-server = utf8
port = 3307
socket = /home/mall/mysql/tmp/mysql.sock
socket =
user = umeng
skip-external-locking
datadir = /home/mall/mysql/data/
log-error = /home/mall/mysql/log/mysqld.err
pid-file = /home/mall/mysql/log/mysql.pid
#init_connect='set autocommit=0'
#init_connect='set names utf8'
#read-only
key_buffer_size = 64M
myisam_sort_buffer_size = 2048M
max_allowed_packet = 16M
table_open_cache = 4096
sort_buffer_size = 3M
join_buffer_size = 3M
read_buffer_size = 3M
read_rnd_buffer_size = 5M
bulk_insert_buffer_size = 64M
query_cache_size = 64M
query_cache_type = 2
query_cache_limit=512k
query_cache_min_res_unit = 2k
tmp_table_size=32M
max_tmp_tables=128
max_heap_table_size = 256M
open_files_limit=102400
thread_concurrency = 16
max_connections=3000
max_connect_errors=3000
back_log = 600
#table_cache = 4096
thread_cache_size = 300
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
skip-name-resolve
####log variables
server-id = 13243
binlog_format=mixed
#log-slave-updates
log-bin = /home/mall/mysql/log/mysql-bin
relay_log = /home/mall/mysql/log/relay-bin
max_binlog_size = 500M
binlog_cache_size = 1M
max_binlog_cache_size = 4096M
#binlog-ignore-db = mysql
replicate-ignore-db = mysql
expire-logs-days = 8
sync_binlog=20
binlog-do-db=ucgc_dzms
binlog-ignore-db=mysql
log-slave-updates
slow_query_log=1
slow_query_log_file = /home/mall/mysql/log/slowquery.log
long_query_time=1
general_log=off
general_log_file = /home/mall/mysql/log/general.log
#relay_log_purge=OFF
# Point the following paths to different dedicated disks
#tmpdir = /tmp/
#log-update = /path-to-dedicated-directory/hostname
#auto_increment_increment=1
#auto_increment_offset=1
####innodb variables
#skip-innodb
#ignore_builtin_innodb
innodb_data_home_dir = /home/mall/mysql/data/
innodb_data_file_path = ibdata1:12M;ibdata2:100M:autoextend
innodb_autoextend_increment = 64
innodb_log_group_home_dir = /home/mall/mysql/data/
#innodb_log_arch_dir = /home/mall/mysql/log/
innodb_buffer_pool_size = 180M
innodb_additional_mem_pool_size = 32M
innodb_log_file_size = 360M
innodb_log_buffer_size = 8M
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 2
#innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_thread_sleep_delay = 100
default-storage-engine=innodb
innodb_max_dirty_pages_pct = 50
#innodb_lock_wait_timeout = 60
#innodb_file_per_table = 0
#innodb_support_xa=1
#innodb_io_capacity=200
innodb_flush_method=O_DSYNC
innodb_force_recovery=1
#interactive_timeout = 600
#wait_timeout = 900
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 5M
write_buffer = 5M
[mysqlhotcopy]
interactive-timeout
修改数据库字符集##
alter database mall character set utf8mb4;
QA
1. 远程MySQL工具登录不上,可能是防火墙未开放MySQL端口访问权限
关闭防火墙
1.1、重启后永久性生效:
开启:chkconfig iptables on
关闭:chkconfig iptables off
1.2、即时生效,重启后失效:
开启:service iptables start
关闭:service iptables stop
2. MySQL安装过程中遇到的问题
http://blog.csdn.net/yaoqinglin/article/details/45269247
3. 执行SQL文件
source /root/mysql/init_sql/init.sql
4. 缺少libaio.so.1包
[[email protected]_api lib64]# yum list | grep 'libaio-dev'
libaio-devel.i686 0.3.107-10.el6 base
libaio-devel.x86_64 0.3.107-10.el6 base
[[email protected]_api lib64]#
[[email protected]_api lib64]# yum install libaio-devel
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
* base: mirror.amsiohosting.net
* extras: nl.mirror.babylon.network
* updates: mirror.amsiohosting.net
Resolving Dependencies
--> Running transaction check
---> Package libaio-devel.x86_64 0:0.3.107-10.el6 will be installed
--> Processing Dependency: libaio = 0.3.107-10.el6 for package: libaio-devel-0.3.107-10.el6.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
5. 修改root密码
mysql> set password =password('123456');
刷新权限
mysql> flush privileges;
root账号就正常使用了。
资料
MySql my.cnf
MySQL如何避免使用Linux的swap分区而提升读写性能
SWAP的罪与罚
MySQL 内存占用过高分析
MySQL命令行--导入导出数据库
MySQL字符集utf8mb4
推荐阅读
-
PHP开发环境配置(MySQL数据库安装图文教程)
-
Microsoft SQL Server 2012 数据库安装图解教程
-
oracle数据库不需要安装客户端就能通过vs链接数据库的方法
-
ubuntu 16.04 数据库mysql安装与管理
-
Linux安装配置MariaDB数据库全程详解
-
在sqlserver2005中安装sql server 2000的示例数据库northwind的方法
-
CentOS 7.4下安装Oracle 11.2.0.4数据库的方法
-
mysql 5.7 数据库安装步骤个人总结
-
C#简单访问SQLite数据库的方法(安装,连接,查询等)
-
DBA 在Linux下安装Oracle Database11g数据库图文教程