以安装在/home目录下为例
1.下载安装包地址:https://dev.mysql.com/downloads/file/?id=476936,安装包保存到/home
2.添加用户组和用户
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -r -g mysql mysql
3.解压:
cd /home
tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
4.安装
cd /home/mysql
mkdir data
mkdir log
chown -R mysql:mysql /home/mysql
5.初始化文件
./bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
6.复制启动文件
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp ./bin/my_print_defaults /usr/bin/
7.修改启动脚本
vi /etc/init.d/mysqld
#修改项:
basedir=/home/mysql
datadir=/home/mysql/data
8.#加入环境变量,编辑 /etc/profile
vi /etc/profile
#添加mysql路径,加入下面内容:
export PATH=$PATH:/home/mysql/bin
#刷新立即生效
source /etc/profile
9.修改mysql配置项
vi /etc/my.cnf
配置如下(覆盖到my.cnf中):
[client]
port = 3306
socket = /home/mysql/lib/mysql.sock
default-character-set = utf8
[mysql]
prompt="MySQL [\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /home/mysql/lib/mysql.sock
character-set-server = utf8
basedir = /home/mysql
datadir = /home/mysql/data
pid-file = /home/mysql/lib/mysql.pid
general_log_file = /home/mysql/log/mysql.log
log_error = /home/mysql/log/mysql_error.log
slow_query_log_file = /home/mysql/log/mysql_slow.log
user = mysql
server-id = 21
log_bin = mysql-bin
binlog_format = row
expire_logs_days = 7
#master-master replication
gtid_mode = on
enforce_gtid_consistency = on
relay_log_info_repository = TABLE
master_info_repository = TABLE
relay_log_recovery = on
sync_master_info = 1
slave_parallel_workers = 2
binlog_checksum = CRC32
master_verify_checksum = 1
slave_sql_verify_checksum = 1
binlog_rows_query_log_events = 1
slave_parallel_type=logical_clock
#skip-name-resolve
#skip-networking
max_connections = 2000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 1024
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 128M
slow_query_log = 1
long_query_time = 2
explicit_defaults_for_timestamp
#lower_case_table_names = 1
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 1024M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
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
[mysqldump]
quick
9.启动mysql
service mysqld start 或者 /etc/init.d/mysqld start
如启动失败:
根据具体报错信息进行修改
删除 /home/mysql-5.7.22/data下所有文件,重新执行./bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data,再启动
如果登录密码错误:
#杀掉进程
pkill mysql
#确认mysql进程被杀掉
ps aux |grep mysql
#忽略授权表登录
./bin/mysqld_safe --skip-grant-tables &
10.进入mysql修改初始密码,修改远程连接的用户权限问题
mysql -uroot -p
alter user 'root'@'localhost' identified by 'gome123'; OR
set authentication_string=password('gome123'); OR
update mysql.user set authentication_string=password('gome123') where user ='root' and host='localhost';
flush privileges;