一、准备工作
- mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz,下载地址;
二、创建MySQL用户
三、解压安装包
四、修改配置文件
- 复制my.cnf配置文件
[client] port = 3306 socket = /tmp/mysql3306.sock secure_auth = false [mysqld] port = 3306 socket = /tmp/mysql3306.sock datadir = /home/mysql/mysql3306 #read_only = on #--- GLOBAL ---# character_set_server = utf8 lower_case_table_names = 1 log-output = FILE log-error = /home/mysql/logs/mysql-error.log #general_log general_log_file = /home/mysql/logs/mysql.log pid-file = /home/mysql/mysql.pid slow-query-log = 1 slow_query_log_file = /home/mysql/logs/mysql-slow.log tmpdir = /tmp/ long_query_time = 2 innodb_force_recovery = 0 #innodb_buffer_pool_dump_at_shutdown = 1 #innodb_buffer_pool_load_at_startup = 1 #--------------# #thread_concurrency = 8 thread_cache_size = 51 table_open_cache = 16384 open_files_limit = 65535 table_definition_cache = 16384 sort_buffer_size = 2M join_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 8M key_buffer_size = 32M bulk_insert_buffer_size = 16M myisam_sort_buffer_size = 64M tmp_table_size = 32M max_heap_table_size = 16M query_cache_size = 32MB #gtid_mode=on #log_slave_updates=1 #enforce_gtid_consistency=1 #--- NETWORK ---# back_log = 103 max-connections = 512 max_connect_errors = 100000 max_allowed_packet = 32M interactive_timeout = 600 wait_timeout = 600 skip-external-locking #max_user_connections = 0 external-locking = FALSE #skip-name-resolve #--- REPL ---# server-id = 1103306 sync_binlog = 1 log-bin = mysql-bin binlog_format = row expire_logs_days = 10 relay-log = relay-log replicate-ignore-db = test log_slave_updates =1 #skip-slave-start binlog_cache_size =4M max_binlog_cache_size =8M max_binlog_size =1024M #--- INNODB ---# default_storage_engine = InnoDB innodb_data_file_path = ibdata1:1024M:autoextend innodb_buffer_pool_size = 1040M innodb_buffer_pool_instances = 1 innodb_additional_mem_pool_size = 16M innodb_log_files_in_group = 2 innodb_log_file_size = 256MB innodb_log_buffer_size = 16M innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 30 innodb_flush_method = O_DIRECT innodb_max_dirty_pages_pct = 75 innodb_io_capacity = 200 innodb_thread_concurrency = 32 innodb_open_files = 65535 innodb_file_per_table = 1 transaction_isolation = REPEATABLE-READ innodb_locks_unsafe_for_binlog = 0 #innodb_purge_thread = 4 skip_name_resolve = 1 [mysqldump] quick max_allowed_packet = 32M [mysql] auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates default_character_set=utf8 [mysqlhotcopy] interactive-timeout
字段解释
#字段解释# [mysqld] port = 3306 mysql的启动的端口 socket = /tmp/mysql3306.sock (在启动的时候mysqld会自动生成,以socket文件的通信性质,只能本地登录) datadir = /home/mysql/mysql3306 (数据目录) log-error = /home/mysql/logs/mysql-error.log (INFO WARN ERROR) server-id = 1103306(IP后两位+端口 192.168.1.10 3306) innodb_buffer_pool_size = 512M (50%--75%)内存的总大小
五、配置服务
vi /etc/init.d/mysqld 修改两处位置: basedir=/usr/local/mysql datadir=/data/mysql_data
六、初始化MySQL (只需要做一次)
七、配置环境变量
#在"/etc/profile"中添加如下配置 export MYSQL_HOME=/usr/local/mysql PATH=$PATH:$MYSQL_HOME/bin
八、启动MySQL服务
- 删除系统中其他数据库客户端(若安装过其他数据库);
rm -rf /usr/bin/mysql* ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
九、进入数据库
2.通过用户名及密码登录数据库客户端(前提是配置了密码)
mysql -uroot -p
十、权限管理
- 查看用户信息;
select user,host,password from mysql.user; - 设置root本地权限及密码;
grant all on *.* to root@'localhost' identified by 'root'; - 删除没有密码的用户,并创建jack用户;
delete from mysql.user where password ='';
十一、进入数据库流程