[置顶] mysql5.7在centos上安装的完整教程以及相关的“坑”
mysql,mysql5.7,mysql5.7安装,mysql5.7优化,mysql优化2016-11-25
Step1: 如果你系统已经有mysql,如一般centos自带mysql5.1系列,那么你需要删除它,先检查一下系统是否自带mysql
yum list installed | grep mysql
yum -y remove mysql-libs.x86_64
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm yum localinstall mysql-community-release-el6-5.noarch.rpm yum repolist all | grep mysql yum-config-manager --disable mysql55-community yum-config-manager --disable mysql56-community yum-config-manager --enable mysql57-community-dmr yum repolist enabled | grep mysql
yum install mysql-community-server
service mysqld start
chkconfig --list | grep mysqld chkconfig mysqld on
service mysqld stop mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -uroot -p
就可以登录mysql了
Step3: 更改mysql安全密码
先説一下原因,mysql5.7出现这样的问题,是因为MYSQL5.6之后,加强了对安全性的管控,认为root用户进行mysql操作是一种危险的行为,于是限制了root用户登录mysql()。但是我们可以通过修改Mysql中user表的方法解决该问题
(网络上还有一种做法是查看/var/log/mysql.log,该文件内有安装后Mysql生成的随机密码,然后用文件里的密码正常登录即可,有兴趣者自己可以试下,此处使用正规操作步骤)
mysql> SET PASSWORD = PASSWORD('ur password here');
update mysql.user set authentication_string=password('newpassword') where user='root'
之前的mysql版本为:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ur password here' WITH GRANT OPTION;
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. join_buffer_size = 128M sort_buffer_size = 6M read_rnd_buffer_size = 4M #deprecate this option after mysql5.5 default-character-set = utf8 character-set-server=utf8 open_files_limit = 10240 back_log = 384 max_connections = 500 #deprecate this option after mysql5.5 table_cache = 512K max_allowed_packet =16M query_cache_size = 384M table_open_cache = 512 key_buffer_size = 384M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid slow_query_log_file = /var/log/mysqld-slow-query.log log-short-format long-query-time = 3 #log-long-format #log-slow-admin-statements log-queries-not-using-indexes