在linux系统上安装mysql数据库

时间:2022-05-07 17:07:38

一、解压tar包

#tar zxvf mysql-5.6-linux-glibc2.5-x86_64.tar.gz

改名

#mv mysql-5.6-linux-glibc2.5-x86_64 mysql

二、创建用户
#useradd mysql

#passwd mysql

三、修改目录权限

#chown -R mysql:mysql mysql
#su - mysql



四、创建参数文件(路径修改成自己的)
#vi my.cnf


复制粘贴以下内容到my.cnf文件中


##===========================================================
[client]
port = 3306
socket = /u01/app/mysql/mysql.sock
default-character-set=utf8






[mysqld]
port = 3306
user = mysql
basedir = /opt/mysql
datadir = /opt/mysql/data
socket = /opt/mysql/mysql.sock
character-set-server=utf8
long_query_time = 2
slow_query_log = /opt/mysql/logs/slow.log
expire_logs_days = 7
# server-id = 35
# binlog_format = MIXED
# log-bin = /opt/mysql/logs/mysql-bin
# binlog_cache_size = 4M
# max_binlog_cache_size = 8M
# max_binlog_size = 512M 
# log_bin_trust_function_creators=TRUE
#############################################
symbolic-links=0
skip-external-locking
lower_case_table_names=1
default_storage_engine=InnoDB
back_log = 500
max_connections = 2000
max_connect_errors = 5000
external-locking = FALSE
max_allowed_packet = 32M
thread_cache_size = 300
thread_stack = 192K




## Other parameters #######################
thread_concurrency = 48
#thread_concurrency = Logical CPU*2
query_cache_size = 32M
query_cache_limit = 4M
query_cache_min_res_unit = 4k
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 2048M
join_buffer_size=64M
read_buffer_size = 10M
read_rnd_buffer_size = 16M
sort_buffer_size = 32M
bulk_insert_buffer_size = 64M




## Innodb parameters #####################
innodb_buffer_pool_size = 2G
innodb_file_io_threads = 4
innodb_thread_concurrency = 48
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
innodb_flush_method = O_DIRECT
innodb_use_native_aio = 1
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_additional_mem_pool_size = 40M



sql_mode=NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES,STRICT_TRANS_TABLES



[mysqld_safe]
pid-file = /opt/mysql/mysqld.pid
log-error = /opt/mysql/logs/mysql.err


##===========================================================




五、初始化,初始化mysql表、test表、infomation表等


#scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data



六、创建日志目录
#cd /opt/mysql

#mkdir logs/



七、启动服务(必须在mysql家目录下启动)
#/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/my.cnf
后台启动服务
#/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/my.cnf &


八、进入mysql客户端
#/opt/mysql/bin/mysql -uroot -p -S /opt/mysql/mysql.sock

mysql>show databases;


九、退出mysql

mysql>exit;


十、关库并停止服务
#/opt/mysql/bin/mysqladmin -uroot -p -S /opt/mysql/mysql.sock shutdown