[root@localhost tools]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql [root@localhost local]# cd mysql [root@localhost mysql]# mkdir database [root@localhost mysql]# mkdir data [root@localhost mysql]# mkdir data/relay [root@localhost mysql]# mkdir data/tmp [root@localhost mysql]# chmod -R 755 data [root@localhost mysql]# ls bin data database docs include lib LICENSE man README share support-files [root@localhost mysql]# ls data relay tmp
创建mysql用户组和用户并授权目录
1 2 3 4 5 6
[root@localhost mysql]# groupadd mysql [root@localhost mysql]# useradd -r -g mysql mysql [root@localhost mysql]# cd .. [root@localhost mysql]# chgrp -R mysql . [root@localhost mysql]# chown -R mysql . [root@localhost local]# chown -R mysql:mysql mysql
进到myslq目录下安装
1 2 3 4 5 6 7 8 9
[root@localhost local]# cd mysql [root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/database 2019-11-17T01:26:52.844368Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-11-17T01:26:53.159085Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-11-17T01:26:53.240493Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-11-17T01:26:53.313258Z 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: 5611788c-08d9-11ea-96df-005056b8be6e. 2019-11-17T01:26:53.317771Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-11-17T01:26:54.551802Z 0 [Warning] CA certificate ca.pem is self signed. 2019-11-17T01:26:54.812906Z 1 [Note] A temporary password is generated for root@localhost: laj3w?hlor:M
[root@localhost mysql]# chkconfig --add mysql [root@localhost mysql]# chkconfig --level 2345 mysql on
启动 mysql
1 2
[root@localhost mysql]# service mysql start Starting MySQL. [ OK ]
修改root密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[root@localhost ~]# mysql -u root -p Enter password:laj3w?hlor:M ##密码根据实际来 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.28 Copyright (c) 2000, 2019, 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'forhelp. Type '\c' to clear the current input statement. mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> set password = password('root'); ##密码也设置成root Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql默认情况下只能本地访问,需要设置可以远程访问,接着上面继续
1 2 3 4 5 6 7 8 9 10
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set Host = "%"where user = 'root'; ##刷新缓存 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
[root@localhost tools]# mysql -u root -p Enter password:root ##上面修改过的密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.28 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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'forhelp. Type '\c' to clear the current input statement. mysql> CREATE DATABASE `dmas` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.01 sec) mysql> use dmas Database changed mysql> source /usr/tools/dump-dmas-201911191055.sql; ##.sql文件是从139这个库导出来的 Query OK, 0 rows affected (0.00 sec) ...... ##此处省略若干执行结果 mysql>