mysql8学习笔记2-非常规安装
承接之前的常规安装,如果想把data目录迁移到别的路径下,可以这么操作:
[root@localhost mysql]# /etc/init.d/mysql stop #首先关闭应用 Shutting down MySQL.. SUCCESS! [root@localhost mysql]# mv ./data /mysql_data #然后迁移data
[root@localhost mysql]# /etc/init.d/mysql start #启动下报错了。 Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). [root@localhost mysql]# vim /etc/my.cnf #修改配置文件,没有就创建,设置目录 [root@localhost mysql]# cat /etc/my.cnf [mysqld] datadir=/mysql_data [root@localhost mysql]# /etc/init.d/mysql start #启动成功 Starting MySQL.. SUCCESS! [root@localhost mysql]#
也可以把整个mysql路径都迁移
[root@localhost mysql]# /etc/init.d/mysql stop Shutting down MySQL.. SUCCESS! [root@localhost mysql]# cd .. [root@localhost local]# mv mysql /mysql [root@localhost local]# ls bin etc games include lib lib64 libexec sbin share src [root@localhost local]# vim /etc/my.cnf [root@localhost local]# cat /etc/my.cnf [mysqld] basedir=/mysql #添加一个mysql路径 datadir=/mysql_data [root@localhost local]# /etc/init.d/mysql start Starting MySQL.. SUCCESS! [root@localhost local]# ps -ef |grep mysql root 70568 1 0 02:01 pts/2 00:00:00 /bin/sh /mysql/bin/mysqld_safe --datadir=/mysql_data --pid-file=/mysql_data/localhost.localdomain.pid mysql 70682 70568 11 02:01 pts/2 00:00:00 /mysql/bin/mysqld --basedir=/mysql --datadir=/mysql_data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/mysql_data/localhost.localdomain.pid root 70728 11777 0 02:01 pts/2 00:00:00 grep --color=auto mysql [root@localhost local]#
也可以在初始化时指定路径
[root@localhost /]# mkdir mysql8 创建新目录 [root@localhost /]# mv mysql ./mysql8/ #迁移mysql路径 [root@localhost /]# mv mysql_data ./mysql8/ #迁移mysqldata路径 [root@localhost /]# ls /mysql8/ mysql mysql_data [root@localhost /]# ls bin boot dev etc home lib lib64 media mnt mysql8 opt proc root run sbin srv sys tmp usr var [root@localhost /]# rm -rf ./mysql8/mysql_data/* #删除mysqldata下数据 [root@localhost /]# cd mysql8/mysql/ [root@localhost mysql]# pwd /mysql8/mysql [root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/mysql8/mysql --datadir=/mysql8/mysql_data & #重新初始化,指定basedir和datadir [1] 71600 [root@localhost mysql]# 2020-06-27T10:12:02.279902Z 0 [System] [MY-013169] [Server] /mysql8/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 71600 2020-06-27T10:12:08.432323Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: aj.+bS%6&!4m 2020-06-27T10:12:12.310996Z 0 [System] [MY-013170] [Server] /mysql8/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed [1]+ Done bin/mysqld --initialize --user=mysql --basedir=/mysql8/mysql --datadir=/mysql8/mysql_data [root@localhost mysql]# mysql -uroot -p -bash: /usr/local/mysql/bin/mysql: No such file or directory [root@localhost mysql]# vim ~/.bash_profile [root@localhost mysql]# cat ~/.bash_profile |grep PATH PATH=$PATH:$HOME/bin:/mysql8/mysql/bin export PATH [root@localhost mysql]# source ~/.bash_profile [root@localhost mysql]# mysql -uroot -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) [root@localhost mysql]# /etc/init.d/mysql start /etc/init.d/mysql: line 239: my_print_defaults: command not found /etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe) [root@localhost mysql]# vim /etc/my.cnf [root@localhost mysql]# cat /etc/my.cnf [mysqld] basedir=/mysql8/mysql datadir=/mysql8/mysql_data [root@localhost mysql]# /etc/init.d/mysql start Starting MySQL.Logging to '/mysql8/mysql_data/localhost.localdomain.err'. .. SUCCESS! [root@localhost mysql]# 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> alter user user() identified by 'mysql'; Query OK, 0 rows affected (0.03 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql>