mysql5.7安装及设置root密码

192人浏览 / 0人评论

1、增加/etc/yum.repo.d/mysql-community.repo

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

2、执行yum安装

sudo yum install -y mysql-community-server

3、修改配置文件(/etc/my.cnf)

[mysqld]
socket          = /data/mysql/mysql.sock
default-time-zone = '+8:00'
key_buffer_size = 1024M
max_allowed_packet = 16M
table_open_cache = 1024
sort_buffer_size = 128M
read_buffer_size = 128M
read_rnd_buffer_size = 32M
myisam_sort_buffer_size = 364M
myisam_max_sort_file_size = 10G
thread_cache_size = 64
query_cache_size= 256M
query_cache_type=1
query_cache_limit=2M
innodb_thread_concurrency = 16
max_connections=1000
max_connect_errors=10000
max_heap_table_size = 64M
tmp_table_size = 32M
ft_min_word_len=1
ft_stopword_file=
delay_key_write=ALL
tmp_table_size=800M
tmpdir  = /tmp/
skip-name-resolve
wait_timeout = 28800
interactive_timeout = 28800
group_concat_max_len = 102400

character-set-server=utf8
server-id = 81
binlog_format = row
log-error=/data/mysql/2_7_81-error.log
pid-file=/data/mysql/2_7_81.pid
datadir = /data/mysql/

log-bin=/data/mysql/2_7_81-bin
log-bin-index=/data/mysql/2_7_81-bin.index
log_bin_trust_function_creators=1

log_slave_updates
expire_logs_days=15

relay-log=/data/mysql/2_7_81-srelay.log
relay_log_purge=1

slow_query_log = 1
slow_query_log_file=/data/mysql/2_7_81-slowquery.log
long_query_time=10

innodb_file_per_table=1
innodb_write_io_threads=8
innodb_read_io_threads=8
innodb_lock_wait_timeout=300
innodb_large_prefix=on

ft_min_word_len = 1
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]
quick
max_allowed_packet=512M
default-character-set=utf8
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[client]
socket          = /data/mysql/mysql.sock

主要修改datadir、socket的路径

4、启动mysql

service mysqld restart

5、设置不用密码就可以登录

mysql能够正常启动后,先修改/etc/my.cnf,在[mysqld]下添加skip-grant-tables,意思是数据库启动的时候 跳跃权限表的限制,不用验证密码,直接登录

[myslqd]
... 
skip-grant-tables
...

保存后重启服务

service mysqld restart

6、登录

mysql -uroot -p

直接回车就可以登录进去

7、修改root密码

登录后,执行

update mysql.user set authentication_string=password('123456') where user= 'root'; 
FLUSH PRIVILEGES;

即:设置root用户的密码是123456。下次登录就可以使用密码登录。注意要将/etc/my.cnf中skip-grant-tables去掉,并重启mysqld服务

全部评论