我这是centos系统:https://dev.mysql.com/downloads/file/?id=481117
(本人习惯放在opt目录下)
[root@instance-61ibcsrp opt]# mkdir softwares
[root@instance-61ibcsrp opt]# mkdir modules
[root@instance-61ibcsrp softwares]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /opt/modules/
[root@instance-61ibcsrp modules]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
[root@instance-61ibcsrp mysql]# mkdir data
[root@instance-61ibcsrp modules]# groupadd mysql
[root@instance-61ibcsrp modules]# useradd -g mysql mysql
[root@instance-61ibcsrp modules]# chown -R mysql:mysql *
[root@instance-61ibcsrp mysql]# ./bin/mysqld --user=mysql --basedir=/opt/modules/mysql --datadir=/opt/modules/mysql/data --initialize
2018-11-20T10:10:19.428029Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_tim
2018-11-20T10:10:19.736708Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-20T10:10:19.805795Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-20T10:10:19.960456Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server aeeb-000c2937887c.
2018-11-20T10:10:19.965735Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-20T10:10:19.975224Z 1 [Note] A temporary password is generated for root@localhost: ezsS+hnXq0wp
记下初始密码:ezsS+hnXq0wp
[root@instance-61ibcsrp mysql]# chown -R root .
[root@instance-61ibcsrp mysql]# chown -R mysql data
修改以下内容
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/opt/modules/mysql
bindir=/opt/modules/mysql/bin
if test -z "$datadir"
then
datadir=/opt/modules/mysql/data
fi
sbindir=/opt/modules/mysql/bin
libexecdir=/opt/modules/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
[root@instance-61ibcsrp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@instance-61ibcsrp mysql]# chmod 755 /etc/init.d/mysqld
[root@instance-61ibcsrp mysql]# cp bin/my_print_defaults /usr/bin/
[root@instance-61ibcsrp mysql]# vi /etc/init.d/mysqld
修改的内容:
basedir=/opt/modules/mysql/
datadir=/opt/modules/mysql/data
port=3306
[root@instance-61ibcsrp mysql]# service mysqld start
[root@instance-61ibcsrp mysql]# vi /etc/profile
加入以下内容
#mysql
export PATH=$PATH:/opt/modules/mysql/bin
刷新配置使其生效
[root@instance-61ibcsrp mysql]# source /etc/profile
密码为上面记下的初始密码:ezsS+hnXq0wp
[root@instance-61ibcsrp mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 61
Server version: 5.7.24
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>
改为123456
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
首先:找到找到mysqld的路径
[root@instance-61ibcsrp mysql]# which mysqld
/opt/modules/mysql/bin/mysqld
然后:根据mysqld路径找到my.cnf配置文件路径
[root@instance-61ibcsrp mysql]# /opt/modules/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options'
mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)
2018-11-20T06:07:43.563765Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
最后:用notepad++配置该文件
[root@instance-61ibcsrp mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.7.24 MySQL Community Server (GPL)
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
进入mysql,修改user表里user字段值为root的host字段的值:
若要让所有人都能远程连接,则赋值“%”,
若只给某一台电脑赋值,则直接赋值其ip