标签:
由于公司临时让将Oracle的数据移植到mysql上面,所以让我在公司服务器上面安装一下mysql。下面就是我的安装过程以及一些错误解决思路。其实对于不同版本安装大体都有差不多。
mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
官网: http://dev.mysql.com/downloads/mysql/
#rpm -qa|grep -i mysql
mysql-5.7.13-linux-glibc2.5-x86_64
*可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系:
#rpm -e mysql-5.7.13-linux-glibc2.5-x86_64 --nodeps
当然你的也可能不止这一个文件,也可能有多个,那么你就依次 rpm -e xx --nodeps 卸载,卸载完了再检查一下,若确定删除干净后,在经行下面步骤。
在这步之前一定要先确保你所建的用户以及用户组没有存在,要不然在后面的过程中会报错。
userdel mysql # 删除用户名
groupdel mysql # 删除用户组名
# groupadd mysql # 创建一个名为mysql的用户组
# useradd -g mysql -d /home/mysql mysql # 在用户组下创建用户
# mkdir /home/mysql/data # 创建文件夹
# tar -xzvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz # 解压文件
# cd mysql-5.7.9-linux-glibc2.5-x86_64 # 进入
# mv * /home/mysql # 移动到之前我创建的mysql文件夹下。
# cd /home/mysql # 进入安装目录
# ./bin/mysql_install_db --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data 2015-11-10 02:09:17
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2015-11-10 02:09:23 [WARNING] The bootstrap log isn‘t empty: 2015-11-10 02:09:23
[WARNING] 2015-11-10T10:09:18.114182Z 0
[Warning] --bootstrap is deprecated. Please consider using --initialize instead 2015-11-10T10:09:18.129343Z 0
[Warning] Changed limits: max_open_files: 1024 (requested 5000) 2015-11-10T10:09:18.129408Z 0
[Warning] Changed limits: table_open_cache: 431 (requested 2000)
mysql5.7新特性:由上面可以看出, mysql_install_db
已经不再推荐使用了,建议改成 mysqld --initialize
完成实例初始化。
# ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
# ./mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize 2016-04-08T01:46:53.153530Z 0
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-04-08T01:46:53.155856Z 0
[ERROR] --initialize specified but the data directory has files in it. Aborting. 2016-04-08T01:46:53.155879Z 0
[ERROR] Aborting
出现上面的错误是因为我们没有清空mysql的data目录, 执行清空命令如下:
# cd /home/mysql/data
# 进入安装目录下的data目录
# rm -fr * # 清空数据
# ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize 2016-04-08T01:47:57.556677Z 0
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-04-08T01:47:59.945537Z 0
[Warning] InnoDB: New log files created, LSN=45790 2016-04-08T01:48:00.333528Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-04-08T01:48:00.434908Z 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: ece26421-fd2b-11e5-a1e3-00163e001e5c. 2016-04-08T01:48:00.440125Z 0
[Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2016-04-08T01:48:00.440904Z 1 [Note] A temporary password is generated for root@localhost: **mjT,#x_5sW
牢记上面的随机密码, 如上**mjT,#x_5sW
, 下面我们修改密码时需要用到。
# cd /home/mysql
# ./support-files/mysql.server start
Starting MySQL.. OK!
这是正常的情况下。
刚刚我用的是/home/mysql
为mysql的安装目录basedir, 则在启动服务时会出现如下错误:
# ./support-files/mysql.server start
./support-files/mysql.server: line 276: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
由上面可知mysql的tar.gz安装包的默认安装目录为/usr/local/mysql
, 这时候我们需要修改/support-files/mysql.server
文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径, 如下:
# vim support-files/mysql.server
--------------------------
...
basedir=/home/mysql
datadir=/home/mysql/data
...
--------------------------
# ./support-files/mysql.server
start Starting MySQL.. OK!
上面红字部分收手动改的,那么在命令中如何手动改,步骤
1、 按 键盘 i 键(insert),然后就可以在你想要的位置编写了。
2、编辑完毕退出,esc键。
3、Shift键 加 :(冒号键)退出编辑。
4、wq! 保存编辑
# ln -s /home/mysql/bin/mysql /usr/bin/mysql
下面的前3步操作过程中,可能会出错,如果有错就跳过,因为不同电脑的环境不一样,
1、将默认生成的my.cnf备份
# mv /etc/my.cnf /etc/my.cnf.bak
2、进入mysql的安装目录支持文件目录
# cd /home/mysql/support-files
3、拷贝配置文件模板为新的mysql配置文件,
# cp my-default.cnf /etc/my.cnf
4、设置编码,可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行.
如下是我修改配置文件/etc/my.cnf, 设置编码为utf8以防乱码
# vim /etc/my.cnf
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
character_set_server=utf8
init_connect=‘SET NAMES utf8‘
[client]
default-character-set=utf8
有的使用这个命令后,前3步有问题的这里可能my.cnf文件是空的,这个不要紧,既然没有生成,那么你就自己编辑喽!具体编辑怎么实现就参照步骤6.
# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld # 拷贝启动文件到/etc/init.d/下并重命令为mysqld
# chmod 755 /etc/init.d/mysqld # 增加执行权限
# chkconfig --list mysqld #
检查自启动项列表中没有mysqld这个,
# chkconfig --add mysqld #
如果没有就添加mysqld
:
# chkconfig mysqld on #
用这个命令设置开机启动:
# service mysqld start # 启动服务
# service mysqld restart # 重启服务
# service mysqld stop # 停止服务
# cd /home/mysql
# ./bin/mysqladmin -uroot -p‘**mjT,#x_5sW‘ password ‘123456‘ mysqladmin: # 刚刚之前的初始密码
[Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysql> use mysql
Database changed
mysql> update user set authentication_string = PASSWORD(‘123456‘) where user = ‘root‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 1
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.7.13, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 3
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ‘‘
Using delimiter: ;
Server version: 5.7.13 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 1 hour 29 min 17 sec
Threads: 1 Questions: 50 Slow queries: 0 Opens: 136 Flush tables: 1 Open tables: 129 Queries per second avg: 0.009
--------------
[root@testfornss ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
或者:grant all on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
[mysql(0)] 64位Linux下安装mysql-5.7.13-linux-glibc2.5-x86_64
标签:
原文地址:http://www.cnblogs.com/gaojupeng/p/5727069.html