linux 安装 mysql 数据库记录

版权声明:The content of the article comes from WangTwoThree https://blog.csdn.net/weixin_41287692/article/details/85706637

linux 安装 mysql 记录

  1. 上传 mysql 安装包到 /usr/local 下

  2. 创建 mysql 用户

    useradd mysql

    修改mysql密码

    passwd mysql

  3. 解压安装包

tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql
  1. 修改 mysql 目录权限
chown -R mysql:mysql mysql
  1. 创建数据和日志目录
mkdir -p /var/lib/mysql/data /var/lib/mysql/logs /var/lib/mysql/backup /var/lib/mysql/script
  1. 修改目录权限
chown -R mysql:mysql /var/lib/mysql
  1. 初始化 mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql/data
  1. 将 mysql 添加到服务
cp /usr/local/mysql/supports/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld off

chkconfig --levels 35 mysqld on
  1. 编辑 /etc/my.cnf

示例:

[client]

#client character set

default_character_set = utf8

#default login user

user = root

#default password

password = 123



[mysqld]

#########genarel config##########

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#the user runnging mysqld process

user = mysql

#base directory

basedir=/usr/local/mysql

#data directory

datadir=/var/lib/mysql/data

#db server character set

character_set_server = utf8

#default engine

default_storage_engine = innodb

#server id

server_id = 1

#service port

port = 3306

#max connections

max_connections = 1000

#skip resolve name

skip_name_resolve = on

#pid file's directory

pid_file = /var/lib/mysql/logs/mysql.pid



######log part####

#swith on genarel log

general_log = on

#name and directory of genarel log

general_log_file = /var/lib/mysql/logs/m2.general

#swith on binnary log and set the file

log_bin = /var/lib/mysql/logs/m2.bin

#index of bannary log

log_bin_index = /var/lib/mysql/logs/m2-bin.index

#swith bannary log

slow_query_log = on

#name and directory of slow query log

slow_query_log_file = /var/lib/mysql/logs/m2.slow

#the unit of slow log ,second

slow_launch_time=2

#error log setting 

log_error = /var/lib/mysql/logs/m2.err

expire_logs_days = 14



######innodb setting ######

#innodb memory size,byte

innodb_buffer_pool_size=512M

#innodb instance number

innodb_buffer_pool_instances=8

#dump cache from memory to disk when server shutdown

innodb_buffer_pool_dump_at_shutdown=on

#record page cache immediate

innodb_buffer_pool_dump_now=on

#import cache from disk to memory when server startup

innodb_buffer_pool_load_at_startup=on

#immediate cache buffer_pool

innodb_buffer_pool_load_now=on

#log buffer 8M to 32M

innodb_log_buffer_size=8M

#the size of binnary log

innodb_log_file_size=100M

#the action of write log to disk:0--flush per second;1--flush on tranction commit(default); 2--0 and 1

innodb_flush_log_at_trx_commit=1



######MyIsam setting######

key_buffer_size=128M

read_buffer_size=256K

read_rnd_buffer_size=256K

sort_buffer_size=256K

join_buffer_size=256K
  1. 将 mysql 下的 bin 目录添加到 PATH 环境变量中
vi /etc/profile

在文件的结尾输入

PATH=/usr/local/mysql/bin:$PATH

source /etc/profile
  1. 启动mysql服务
service mysqld start
  1. 登陆mysql并修改root用户密码
mysql -u root -p

输入初始化时生成的随机密码

alter user 'root'@'localhost' identified by '123';
  1. 安装完成

猜你喜欢

转载自blog.csdn.net/weixin_41287692/article/details/85706637