系统环境:linux centOS6.8 已经安装过 gcc gcc+(安装过程此处不做重点赘述)
1.以源码形式安装mysql8.0.13,
2.安装目录在/home/data/mysql8013
3.mysql注册到服务
4.本地随处使用mysql客户端命令连接
5.使用navicat等客户端软件可以远程连接
官网:https://downloads.mysql.com/archives/community/
如图:注意选择x64 本系统是64位的。来到这里后,你会发现几乎以往所有版本均可下载,是不是很6呀。
1.将源码安装包上传到即将要安装的路径(/home/data/)
[root@ys data]# pwd
/home/data
[root@ys data]# ll
total 384624
-rw-r--r--. 1 root root 393852364 Dec 9 12:23 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
2.解压源码包
[root@ys data]# tar -Jxvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
3.创建mysql用户和组
[root@ys data]#groupadd mysql
[root@ys data]#useradd mysql -g mysql -p appdb -s /sbin/nologin -M
4.创建软连接
[root@ys data]# ln -s mysql-8.0.13-linux-glibc2.12-x86_64 mysql8013
[root@ys data]# ll
total 384628
lrwxrwxrwx. 1 root root 35 Feb 22 09:24 mysql8013 -> mysql-8.0.13-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 4096 Feb 22 09:21 mysql-8.0.13-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 393852364 Dec 9 12:23 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
5.进入mysql目录并进行权限设置
[root@ys data]# cd mysql8013
[root@ys mysql8013]# chown -R mysql:mysql .
[root@ys mysql8013]# chgrp -R mysql .
6.初始化数据(创建数据存储路径data和初始化root密码等)
[root@ys mysql8013]# ./bin/mysqld --initialize --user=mysql --lower-case-table-names=1 --basedir=/home/data/mysql8013 --datadir=/home/data/mysql8013/data
2019-02-22T01:28:13.094052Z 0 [System] [MY-013169] [Server] /home/data/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 15474
2019-02-22T01:28:22.353419Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ThcS)ieo3Zw9
2019-02-22T01:28:28.952100Z 0 [System] [MY-013170] [Server] /home/data/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server has completed
[root@ys mysql8013]#
其中初始化后,得到的root密码就是:ThcS)ieo3Zw9
请记住,这个是后面在root登陆mysql的时候需要使用到的密码。
7.配置文件修改
[root@ys mysql8013]#cp support-files/my-default.cnf /etc/my.cnf
如果没有此文件,则需要手动创建一个
[root@ys mysql8013]# touch ./support-files/my-default.cnf
将配置文件拷贝到/etc/路径下并编辑
[root@ys mysql8013]# vi /etc/my.cnf
[mysqld]
server-id = 1
port = 3306
mysqlx_port = 33060
mysqlx_socket = /home/data/mysql8013/mysqlx.sock
datadir = /home/data/mysql8013/data
socket = /home/data/mysql8013/mysql.sock
pid-file = /home/data/mysql8013/mysqld.pid
log-error = /home/data/mysql8013/mysqld.log
slow-query-log = 1
slow-query-log-file = slow.log
long_query_time = 0.2
log-bin = bin.log
relay-log = relay.log
binlog_format = ROW
relay_log_recovery = 1
character-set-client-handshake = FALSE
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect ='SET NAMES utf8'
innodb_buffer_pool_size = 1G
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_timestamps = SYSTEM
lower_case_table_names = 1
max_connections = 1000
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /home/data/mysql8013/mysql.sock
default-character-set=utf8
8.设置启动添加到服务中(完成后可以以服务形式启动)
[root@ys mysql8013]# cp -ri /home/data/mysql8013/support-files/mysql.server /etc/init.d/mysql
[root@ys mysql8013]#chmod +x /etc/init.d/mysql
[root@ys mysql8013]#vi /etc/init.d/mysql
basedir=/home/data/mysql8013
datadir=/home/data/mysql8013/data
[root@ys mysql8013]#chkconfig --add mysql
[root@ys mysql8013]#chkconfig mysql on
9.本机随处可以客户端命令形式连接到mysql服务(二选其一)
方法一:使用软连接
[root@ys mysql8013]# ln -s /home/data/mysql8013/bin/mysql /usr/bin/mysql
方法二:将命令程序拷贝到/usr/bin
[root@ys mysql8013]# cp -ri ./bin/mysql /usr/bin/mysql
10.启动mysql服务
[root@ys mysql8013]# service mysql start
Starting MySQL.2019-02-22T01:44:50.833064Z mysqld_safe error: log-error set to '/home/data/mysql8013/mysqld.log', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/home/data/mysql8013/mysqld.pid).[FAILED]
秀儿,在这里你也遇到类似的坑了吗?
解决:手动创建这个日志文件并对其修改权限mysqld.log
[root@ys mysql8013]# touch /home/data/mysql8013/mysqld.log
[root@ys mysql8013]# chown mysql:mysql mysqld.log
再次启动:
[root@ys mysql8013]# service mysql start
Starting MySQL..[ OK ]
[root@ys mysql8013]#
这样就成功了!
还没完呢。
读下去。
11.本机连接
[root@ys mysql8013]# mysql -uroot -p
Enter password:
这是输入我们得到的初始化密码:ThcS)ieo3Zw9
[root@ys mysql8013]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
你会发现,连查看数据都会报错,翻译过来意思是:你虽然成功登陆上来了,但我告诉你,想要执行语句在数据库上操作,就必须重置下你的密码,否则,哼哼,门儿都没得~!
好吧,那我乖乖修改密码就是了~_~
mysql> alter user 'root'@'localhost' identified by 'app^_^db';
Query OK, 0 rows affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
mysql>
这样,本机登陆操作就ok啦。
12.使用navicat客户端软件连接
在防火墙放开的前提下!这一步秀儿们都应该不用我提醒了吧。
出现这个报错,其实是因为你的root账号在初始状态下,只有本机访问的权限。还记得这个吗?
mysql>alter user 'root'@'localhost' identified by 'app^_^db';
解决:
在服务器本机登陆到mysql后查看User表中root的权限。
看到了吧,这里只有一个localhost的权限,想要外部远程可以连接就需要给root添加一个权限啦。
mysql> create user 'root'@'%' identified by 'app^_^db';
Query OK, 0 rows affected (0.14 sec)
mysql>
再来查看一下就是两条了。
接下来我们再试试navicat连接。
哈哈,很不幸还是报错,连接不上,不过值得庆幸的是,报错提示信息跟之前不一样了,说明我们把之前报错问题解决了,这里得给你自己鼓励下。干得漂亮!
这个报错呢,其实是由于mysql8.0版本上,加密规则发生了变化,根据提示信息你可以通过升级navicat客户端软件来解决,
不过我是懒得升级,既然加密规则发生变化,那我就从服务端来更改嘛!
解决:
修改root账号的加密方式并设置密码永久不会失效。
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'app^_^db';
Query OK, 0 rows affected (0.11 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'app^_^db' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.11 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
再试!
恭喜你,成功啦!
点进去,来看看,嗯哼!又有个小问题来啦!
为啥我这只显示一个“information_schema”数据库?跟着我的节奏来,不慌!哈哈。
当然还是权限问题啦!默认初始化的root账号在远程连接的时候是没有设置能查看其它数据库权限的。
这个时候,在服务器通过本机登陆修改权限。
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql>
这下就哦了,完美complete!
整个安装过程中容易出问题报错的点:
1.解压后不设置正确的权限会导致初始化报错(创建目录文件等没权限)
2.初始化时参数过多在后面配置文件中如果有相同参数设置时候如果不一致就导致无法启动成功
比如:--lower-case-table-names=1 这个参数是设置mysql是否敏感区分大小(1:不区分,0:区分)写来的。如果初始化的时候不添加这个默认就会被设置为0;后续如果在my.cnf配置文件中想要通过修改这个lower_case_table_names = 1来实现不区分大小写的话,就会启动失败。报错如下:
[ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('0') and data dictionary ('1').
[ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
3.远程连接的时候权限不足导致的问题较多
因此在创建新账号的时候,一定要注意同时设置权限:
例如:
create user 'web_app'@'%' identified WITH mysql_native_password by 'wahaha' PASSWORD EXPIRE NEVER;
访问来源权限:@‘localhost’ @‘%’
数据库访问权限:
grant all on *.* TO 'userName'@'%';
grant all on dbName.* TO 'userName'@'%';
grant select,update on *.* TO 'userName'@'%';
等等。。
最后,祝你好运。如果有遇到其他问题,欢迎留言共同探讨!