当初真是手贱 安装这个mysql5.7.18版本.网上的教程大多数都是5.7以前的,而且即使有5.7版本的要么图炸了要么有其他的问题,以下是我整理的
1.添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。
①groupadd mysql
②useradd -r -g mysql mysql
* useradd -r参数表示mysql用户是系统用户,不可用于登录系统。
* useradd -g参数表示把mysql用户添加到mysql用户组中。
2.将文件解压到/usr/local
①解压二进制文件, tar -zxvf/usr/local/mysql-5.7.18.tar.gz
②mv mysql-5.7.18 mysql 更改mysql目录名称
③cd mysql 进入mysql文件夹,也就是mysql所在的目录,
④更改mysql目录所属的组和用户。更改权限
chown -R mysql .
chgrp -R mysql .
3.初始化 MySQL 配置表
①初始化表配置正确执行步骤:
在mysql目录下执行
mkdir data
bin/mysqld --initialize --user=mysql --basedir=usr/local/mysql --datadir=/usr/local/mysql/data
这里会返回一个密码
②将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。
[plain] view plain copy [root@rhel5-32 mysql]# chown -R root . [root@rhel5-32 mysql]# chown -R mysql data ③复制配置文件
[plain] view plain copy [root@rhel5-32 mysql]# cp support-files/my-default.cnf /etc/my.cnf 这个位置也是个坑 ,my-default.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 = /tmp/mysql.sock character-set-server=utf8 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]
④mysql5.7配置文件需要修改my.cnf关键配置, mysql5.7之前默认配置文件中是有配置项的,不用手动修改
[plain] view plain copy [mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 socket = /tmp/mysql.sock sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
此处有坑 注意这个socket,我本来配置的是/usr/local/mysql/tmp 这个tmp是我创建的文件夹,在服务启动后会在tmp里面自动生成一个mysql.sock 报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 所以把配置改成了socket = /tmp/mysql.sock . 如果你那边报错可以根据路径在指定位置建立一个tmp文件夹 然后把socket指向那个文件夹即socket = /xxx/tmp/mysql.sock
4. 将mysqld服务加入开机自启动项。
[plain] view plain copy #cp mysql.server /etc/init.d/mysql #chmod +x /etc/init.d/mysql 把mysql注册为开机启动的服务 [plain] view plain copy #chkconfig --add mysql
查看是否添加成功 [plain] view plain copy [root@rhel5-32 mysql]# chkconfig --list mysql mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 5.mysql服务的开启和关闭 [plain] view plain copy #/etc/init.d/mysql start 或者 serivce mysql start 或者 bin/mysqld_safe& #/etc/init.d/mysql stop 或者 service mysql stop 或者 bin/mysqladmin -uroot -p
6.加入环境变量 修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码 PATH=$PATH:/urs/local/mysql:/usr/local/mysql/bin export PATH 最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。 7.登录mysql服务 执行:mysql -uroot -p 会提示你输入密码,密码是上面3 . 1返回的 连上后,在做任何操作前,mysql要求要改掉root的密码后才能进行操作。 show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 需要执行:alter user 'root'@'localhost' identified by 'root'; 之后就可以用root密码来登录 Linux下Mysql的常用命令 1130 -Host '' is not allowed to connect to this MySQL server