欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

linux mysql 5.7的安装配置教程

程序员文章站 2022-03-10 19:22:45
1、添加mysq组和用户 groupadd mysql useradd -r -g mysql mysql 2、解压mysql安装包(mysql-5.7.18-linux-g...

1、添加mysq组和用户

groupadd mysql

useradd -r -g mysql mysql

2、解压mysql安装包(mysql-5.7.18-linux-glibc2.5-x86_64.tar)

tar -xvfmysql-5.7.18-linux-glibc2.5-x86_64.tar

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

3、重命名

mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql

4、更改mysql文件夹所属的组合用户

chown -R mysql /usr/local/mysql/

chgrp -R mysql /usr/local/mysql/

5、进入mysql目录 初始化mysql

bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

6、配置mysql

vi /etc/my.cnf 将附件里的内容复制粘贴进去

附件内容如下:

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
skip-grant-tables

back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M

max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8

thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6


server_id=1

innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M


innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on

[mysqldump]
quick

max_allowed_packet = 32M

[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates

[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 8192

注意事项:

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock

这几个目录或文件如果不存在,你需要主动创建好,否则会报错。

这个配置文件中有这么一句话skip-grant-tables 是跳过权限和密码验证的;等后面修改完root密码时,需要把这句话注释掉。

7、mysql命令

cp -a /usr/local/mysql/suport-files/mysql.server /etc/init.d/mysql

service mysql start 启动服务

service mysql status 查看mysql状态

service mysql stop 停止服务

service mysql restart 重启服务

8、启动服务 登入系统

./usr/local/mysql/bin/mysql -uroot -p

9、修改root用户密码

//查看所有用户 use mysql; select * from user \G;

UPDATE mysql.user SET authentication_string = PASSWORD('mypassword') WHERE User = 'root' AND Host = 'localhost';

FLUSH PRIVILEGES;

10、退出mysql

exit