mysql-学习-2

mysql-学习-20170426

 

mysql的安装:

如何下载mysql?

**切记需要从官网下载**

 

 

http://dev.mysql.com 

 

mysql被Oracle收购后引入进来的一个版本概念: DMR

 

xx-net  :FQ工具 非常优秀 

https://github.com/XX-net/XX-Net/wiki/%E4%BD%BF%E7%94%A8Chrome%E6%B5%8F%E8%A7%88%E5%99%A8

 

下载页面:

https://dev.mysql.com/downloads/mysql/

 

下载linux-generic  如果打不开,需要打开防火墙,因为被墙了! :(

 就下载64位的:

 

 #md5sum  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 
ebc8cbdaa9c356255ef82bd989b07cfb  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 
 

 其他的下载源:

5.7版本后rpm包里面没有mysqld_safe这个命令了

这是和tar.gz包的区别

 

 -------------安装MySQL---------------

 

安装mysql需要关闭numa,方法:

 

 

  numctl –interleave=all  /path/mysqld --defaults-file=/path/my.cnf &

 

 如何检查numa是否开启的呢?
方法:numactl  --show

pt命令

numactl命令 显示

 

 rpm -qa |grep numa

 numact --hardware 这个据说不错
 

 

 希望看不到这个,mysql希望是一个node,所以要关闭numa

下面是oracle的在线关闭方法,

 

最好找运维维护窗口进行关闭numa

 

上面标记红色的两个参数对mysql影响很大,需要优化,

 

 

 unlimit -Sn 65535  

 

 unlimit -Su 10000 
 
-S指的软soft limit限制
-H对应的hard limit限制

 

优化方法: 

ulimit -Sn 65535 
ulimit -Su 10000 

 也可以通过 /etc/security/limits.conf  修改这个文件进行调整

 
swap的分配:限制很少有再分配swap的了  
要么不分配
要么最多4G 足以
 

 

终端的界面显示配置:
 【冒泡】A574-安良-北京(919893326)  21:27:28
老师 发下你的终端提示符配置呗
【管理员】吴炳锡(82565387)  21:28:04
zst_ps1()
{
    Date=$(date +%F)
    Time=$(date +%H:%M:%S)
 
    PS1="\\n\[\e[1;37m[\e[m\]\[\e[1;32m\u\e[m\]\[\e[1;33m@\e[m\]\[\e[1;35m\h $Time \e[m\]\e[1;36m`pwd`\e[m\e[1;37m]\e[m\n\\$"
}
 
PROMPT_COMMAND=zst_ps1
【管理员】吴炳锡(82565387)  21:28:14
/etc/profile 
【管理员】吴炳锡(82565387)  21:28:19
source /etc/profile 
 
--------------------
在/etc/sysctl.conf里面写sysctl vm.swappiness=0
 【吐槽】A549-林茂昌-广州(448424673)  21:28:41
sysctl.conf
【管理员】吴炳锡(82565387)  21:29:05
#vim /etc/sysctl.conf 
【管理员】吴炳锡(82565387)  21:29:27
 vm.swappiness=0
【管理员】吴炳锡(82565387)  21:29:40
tcp 连接回收及端口重用
【管理员】吴炳锡(82565387)  21:30:24
XFS 
 
关闭selinux  关闭iptables
 
vim /etc/sysconfig/selinux 
关闭selinux方法:setenforce 0 
 
 
MySQL的安装:
1.创建用户和目录:
#groupadd mysql
#useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -M mysql
#id mysql
#mkdir /opt/mysql
 
把下载的安装包解压缩在/opt/mysql里:
#tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /opt/mysql
#cd /usr/local
#ln -s /opt/mysql/mysql-5.7.18xxxxx  mysql
#chown -R mysql.mysql mysql
 
 
二:创建配置文件my.cnf:
配置文件位置:/etc/my.cnf   可以使用叶老师的网上快捷方法进行配置文件的创建,网址:http://zhishutech.net/my-cnf-wizard.html
-------------------------------------

[client]
port = 3306
socket = /tmp/mysql.sock

[mysql]
prompt="\u@localhost \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/mysql3306/data/mysql3306.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
#default_table_type = DEFAULT_ENGINE
#default_table_type = InnoDB
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/mysql/mysql3306/data/slow.log
log-error = /data/mysql/mysql3306/data/error.log
long_query_time = 0.1
server-id = 3306
log-bin = /data/mysql/mybinlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2867M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_max_undo_log_size = 4G

# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000

innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_status_file = 1
innodb_status_output = 1
innodb_status_output_locks = 1
innodb_stats_on_metadata = 0

#performance_schema
performance_schema = 1
performance_schema_instrument = '%=on'

#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"

[mysqldump]
quick
max_allowed_packet = 32M

 
 
-------------------------------------
 三:创建mysql的数据,日志,文件路径,规划如下:
datadir  /data/mysql/mysql3306/data
binlog   /data/mysql/mysql3306/logs
           /data/mysql/mysql3306/tmp
 
创建以及授权:
mkdir   /data/mysql/mysql3306/{data,logs,tmp} -p
chown -R mysql.mysql /data/mysql
 
 把mysql放到rhel的启动文件夹中:
 cp support-files/mysql.server /etc/init.d/mysql 
 
创建mysql的环境变量

[root@zst1 22:00:59 /usr/local/mysql]
#mysql
-bash: mysql: command not found

[root@zst1 22:01:56 /usr/local/mysql]
#echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@zst1 22:02:25 /usr/local/mysql]
#echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

[root@zst1 22:02:45 /usr/local/mysql]
#source /etc/profile

[root@zst1 22:02:49 /usr/local/mysql]
#
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

 

截图: 

 
 
4.初始化
cd /usr/local/mysql
./bin/mysqld --defaults-file=/etc/my.cnf --initialize
 
注意:安装 的过程中遇到错误了 比如:

2017-05-01T09:04:21.517575Z 0 [ERROR] unknown variable 'default_table_type=DEFAULT_ENGINE'

2017-05-01T09:12:35.190149Z 0 [ERROR] unknown variable 'innodb_additional_mem_pool_size=16M'
直接注释掉即可。请大家注意!!!!!!!!
 
5.启动
cp support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysql start
 
6.客户端连接
mysql -S /tmp/mysql3306.sock -p
 
 
新版本mysql5.7安装后需要修改密码:

(unknown)@localhost 17:44: [(none)]> ALTER USER USER() IDENTIFIED BY 'pgmfetion';
Query OK, 0 rows affected (0.02 sec)

创建新用户pgm:
root@localhost 17:48: [(none)]> grant all privileges on *.* to 'pgm'@'%' identified by 'pgmfetion' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)

root@localhost 17:49: [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)


 ----------------------------------------------------------------------------------------------------------------

 ldd bin/mysql
查看依赖库是否OK
 
查看错误详细情况使用
perror 13  
perror 1062
perror 42
 
 
 
 
 
 
 
 
 

 

posted @ 2017-04-26 23:10  sainter_007  阅读(697)  评论(0)    收藏  举报