检查是否有安装mysqlrpm -qa|grep mysql
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
rpm -qa|grep mariadb复制代码解压tar包tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz复制代码移动文件mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local复制代码创建日志文件及数据文件cd /usr/local/mysql
mkdir data
mkdir log
cd logtouch mysql-error.log复制代码
创建属组属主并赋权groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql /usr/local/mysql复制代码初始化mysqlcd /usr/local/mysql/bin
./mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#记录初始密码复制代码更改配置文件更改/etc/my.cnf[client]
port = 3306
default-character-set= utf8
socket = /usr/local/mysql/log/mysql.sock
[mysqld]
user = mysql
port = 3306
character-set-server=utf8
socket =/usr/local/mysql/log/mysql.sock
log-bin = /usr/local/mysql/data/log-bin
basedir = /usr/local/mysql
datadir =/usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
skip-name-resolve
back_log = 600
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_binlog_size = 100m
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
query_cache_limit = 2M
key_buffer_size = 4M
ft_min_word_len = 4
transaction_isolation = REPEATABLE-READ
log_bin = mysql-bin
binlog_format = row
expire_logs_days = 30
max_binlog_size = 80m
log_error = /usr/local/mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 3s
low_query_log_file = /usr/local/mysql/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default-storage-engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
max_allowed_packet = 20M
#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M 复制代码更改配置文件/etc/init.d/mysqlbasedir=/usr/local/mysql
datadir=/usr/local/mysql/data复制代码添加开机启动项chkconfig --add mysql
chkconfig mysql onchkconfig --list | grep mysql复制代码修改全局配置文件vim /etc/profile
export MYSQL_HOME="/opt/usr/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
保存退出./etc/profile复制代码启动msyqlservice mysql start
mysql -u root -p
#利用初始化时记住的密码进行登录
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');复制代码创建数据库及赋权CREATE DATABASE `mydb`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
create user 'cqp1116'@'%' identified by 'cqp1116';
grant all privileges on mydb.* to 'cqp1116'@'%';复制代码