简单记录下linux系统下mysql5.7的安装过程:
官网下载地址:http://dev.mysql.com/downloads/mysql/5.7.html#downloads
下载文件:mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@localhost ~]# cat /etc/group | grep mysql
mysql:x:490:
[root@localhost ~]# cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
以上为默认存在的情况,如无,执行添加命令:
[root@localhost ~]#groupadd mysql
[root@localhost ~]#useradd -r -g mysql mysql
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统。
4.解压TAR包,更改所属的组和用户
将mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 解压到 /usr/local/mysql
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
[root@localhost local]# chgrp -R mysql mysql/
5.安装和初始化数据库
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
在安装mysql时遇到以下错误
执行./mysqld --initialize 后
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
原因是没有安装libaio.so.1,安装即可。
Redhat/Fedora/CentOS下执行:yum -y install libaio
再次执行初始化数据库命令时,继续报错:
[root@bogon mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
[root@bogon mysql]# pwd
/usr/local/mysql
[root@bogon mysql]# yum -y install libnuma
再次执行初始化数据库命令,生成的临时密码是 s8:0Ao/.n:te
[root@localhost mysql]# ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysql
[root@localhost mysql]# chkconfig --add mysql //把mysql注册为开启启动项
[root@localhost mysql]# chkconfig --list mysql 查看是否添加成功
[root@localhost mysql]# vi /etc/init.d/mysql
修改内容如下:
basedir=/usr/local/mysqldatadir=/usr/local/mysql/data
如果没有my-default.cnf文件,可以编辑一个my-default.cnf文件,内容如下:
[root@bogon support-files]# vi my-default.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /var/lib/mysql/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
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
修改mysql登陆的密码:
[root@localhost mysql]# cd bin
[root@localhost mysql]# ./mysql -uroot -p
密码上面生成的临时密码
mysql> set password=password("123456");
修改mysql远程登陆:
use mysql;
update user set host='%' where user='root';
如果update失败,mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1,所以才会出现更新失败的情况。
查看变量设置:
mysql> show variables like 'sql_safe%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| sql_safe_updates | ON |
+------------------+-------+
1 row in set (0.06 sec)
先执行 set sql_safe_updates=off;
继续授权操作:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
service mysql restart;
当不在/usr/local/mysql/bin 下执行mysql连接时,抛出如下异常:
root@DB-02 ~]# mysql -u root
-bash: mysql: command not found
原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:
# ln -s /usr/local/mysql/bin/mysql /usr/bin