linux(CentOs6.6) 安装mysql 5.7.18

安装mysql

提前下载好mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 安装包,并上传到指定linux机器上

#安装依赖包
yum search libaio  # search for info
yum install libaio # install library
#新建用户组合用户
groupadd mysql
useradd mysql -g mysql
#解压到data下面
tar -zxvf /data/software/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /data
#重命名
mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql
#安装
cd mysql/
mkdir data
更改所有者
cd ../
chown -R mysql:mysql mysql/
#授权755
chmod -R 755 mysql/
cd mysql
./bin/mysqld --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data --initialize

注意最下面的密码

root@localhost: ==o*s#gqh)F4Ck==

-----注意,初始化数据库会生成登录MySQL数据库的root密码,一定要记住,一会登录数据库要用

2017-04-21T02:36:14.351072Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-04-21T02:36:15.174993Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-04-21T02:36:15.331692Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-04-21T02:36:15.608132Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4ab0413b-263b-11e7-9795-8e59748c97ed.
2017-04-21T02:36:15.615879Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-04-21T02:36:15.620346Z 1 [Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck

先简单测试一下

执行 ./support-files/mysql.server start

mysql 默认配置文件

/usr/local/mysql/support-files/my_default.cnf
也可以复制一份到 /etc/my.cnf 目录下 命名为my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]



sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /var/run/mysqld/mysqld.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

[client]
/bin/bash: Q: command not found

要注意这几个配置:

  • basedir
  • datadir
  • socket

确定指定的文件是否有

修改root用户

进入mysql,查看root用户的详细信息

 # mysql -u root -p
    > use mysql
    > select * from mysql.user where user='root' \G

*************************** 1. row ***************************
                  Host: localhost
                  User: root
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type:
            ssl_cipher:
           x509_issuer:
          x509_subject:
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: *AC241830FFDDC8943AB31CBD47D758E79F7953EA
      password_expired: N
 password_last_changed: 2015-11-11 16:52:49
     password_lifetime: NULL
        account_locked: N
1 row in set (0.00 sec)

把password_expired 改成不过期 && 修改root 密码

mysql> update mysql.user set authentication_string=password('root') where user='root'; 
mysql> update user set password_expired='N' where user='root';
mysql> flush privileges;
mysql> quit

重启服务

#service mysql restart

异常处理

解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using password: YSE)

在ubuntu server 12.04中,安装mysql后,使用命令登录mysql居然报错了,Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using password: YSE),这个错误搞得很郁闷,仔细分析之后,知道这个报错和密码有关,可能是密码在配置mysql的时候异常,所以导致我们没有正确的密码,知道问题后,立即想到解决办法了,那就是重新设置一个密码,方法如下

1.先关闭mysql并设置密码

#sudo  /etc/init.d/mysql stop 
# cd /usr/local/mysql (进入到mysql安装目录)
#sudo  bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
#sudo  mysql -u root mysql 
mysql> update mysql.user set authentication_string=password('root') where user='root'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 

2.重启mysql并尝试登录

#sudo  /etc/init.d/mysql restart 
#sudo  mysql -uroot -p 
Enter password:  
#输入密码,出现下面这个就表示登录正常了 
mysql> 

客户端连接不上时(可能时linux防火墙没有开启mysql 3306 端口)

查看状态:
iptables -L -n
下面添加对特定端口开放的方法:
使用iptables开放如下端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
保存
/etc/rc.d/init.d/iptables save
重启服务
service iptables restart
查看需要打开的端口是否生效?
/etc/init.d/iptables status

法2:
或直接编辑/etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 4000 -j ACCEPT
保存在前面部分
再重启:
service iptables restart

过程使用到的linux命令

Linux删除软链接

mkdir test_chk

touch test_chk/test.txt

vim test_chk/test.txt (这一步随便在这个test.txt里写点东东即可)

下面我们来创建test_chk目录 的软链接

ln-s test_chk test_chk_ln

软链接创建好了,我们来看看怎么删除它

正确的删除方式(删除软链接,但不删除实际数据)

rm -rf ./test_chk_ln

错误的删除方式

rm -rf ./test_chk_ln/ (这样就会把原来test_chk下的内容删除)

Linux启动/停止/重启Mysql数据库的方法

查看mysql版本

方法一:status;
方法二:select version();

2、Mysql启动、停止、重启常用命令
a、启动方式
1、使用 service 启动:
[root@localhost /]# service mysqld start (5.0版本是mysqld)
[root@szxdb etc]# service mysql start (5.5.7版本是mysql)

2、使用 mysqld 脚本启动:
/etc/inint.d/mysqld start

3、使用 safe_mysqld 启动:
safe_mysqld&

b、停止
1、使用 service 启动:
service mysqld stop

2、使用 mysqld 脚本启动:
/etc/inint.d/mysqld stop

3、mysqladmin shutdown

c、重启
1、使用 service 启动:
service mysqld restart
service mysql restart (5.5.7版本命令)

2、使用 mysqld 脚本启动:
/etc/init.d/mysqld restart

你可能感兴趣的:(linux(CentOs6.6) 安装mysql 5.7.18)