mysql的安装

卸载:

https://www.cnblogs.com/taomylife/p/7234925.html

 

mysql router的安装:

 

集群安装示例:

https://my.oschina.net/issume/blog/2239781 

 

 

集群问题:

CREATE DATABASE mysql_innodb_cluster_metadata', Error_code: MY-001007

https://www.jianshu.com/p/6e2918845ec8

error2003不能连接:

https://www.cnblogs.com/ximalaya/p/6711792.html

This member has more executed transactions than those present in the group. Local transactions

https://blog.csdn.net/snowhite91/article/details/83791997

root的账户问题:

http://www.mamicode.com/info-detail-2332414.html 

 

 

 

记住:一定要用域名host映射去连接,不要使用IP去connect;

会出现alter root等报错情况;

 

 

用MySQL 5.5 Command Line Client一闪而过:

http://blog.csdn.net/mixiuali/article/details/9215279

 

安装完没有服务:

https://jingyan.baidu.com/article/e75aca85762f77142edac616.html

http://blog.csdn.net/lxpbs8851/article/details/14161935

 

主要是linux下安装:

安装MySQL主要有两种方法:

一种是通过源码自行编译安装,这种适合高级用户定制MySQL的特性,这里不做说明;

另一种是通过编译过的二进制文件进行安装。

二进制文件安装的方法又分为两种:

一种是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件;

第二种是使用RPM或其他包进行安装,这种安装进程会自动完成系统的相关配置,所以比较方便。

 

两种方法的安装包:

a.  通用安装方法

mysql-5.5.29-linux2.6-x86_64.tar.gz

b.       RPM安装方法:

MySQL-server-5.5.29-2.el6.x86_64.rpm

MySQL-client-5.5.29-2.el6.x86_64.rpm

 

4.       通用安装步骤

a.       检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

*可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

b.     添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。(安全考虑

[root@localhost JavaEE]#groupadd mysql

[root@localhost JavaEE]#useradd -r -g mysql mysql

*useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

c.  将二进制文件解压到指定的安装目录,我们这里指定为/usr/local

[root@localhost ~]# cd/usr/local/

[root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

*加压后在/usr/local/生成了解压后的文件夹mysql-5.5.29-linux2.6-x86_64,这名字太长,我们为它建立一个符号链接mysql,方便输入。

[root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql

d.     /usr/local/mysql/下的目录结构

Directory

Contents of Directory

bin

Client programs and the mysqld server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

e.     进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f.       执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。注意mysql服务进程mysqld运行时会访问data目录,所以必须由启动mysqld进程的用户(就是我们之前设置的mysql用户)执行这个脚本,或者用root执行,但是加上参数--user=mysql。

[root@localhost mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安装目录(解压目录)不是/usr/local/mysql,那么还必须指定目录参数,如

[root@localhost mysql]scripts/mysql_install_db --user=mysql \

         --basedir=/opt/mysql/mysql \

         --datadir=/opt/mysql/mysql/data

*将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

 

g.     复制配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h.  将mysqld服务加入开机自启动项。

*首先需要将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld。

[root@localhostmysql]  cp support-files/mysql.server /etc/init.d/mysqld

*通过chkconfig命令将mysqld服务加入到自启动服务项中。

[root@localhost mysql]#chkconfig --add mysqld

*注意服务名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。

*查看是否添加成功

[root@localhost mysql]#chkconfig --list mysqld

mysqld   0:off 1:off        2:on        3:on        4:on        5:on        6:off

i.  重启系统,mysqld就会自动启动了。

*检查是否启动

[root@localhost mysql]#netstat -anp|grep mysqld

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      2365/mysqld        

unix  2     [ ACC ]     STREAM     LISTENING     14396 2365/mysqld        /tmp/mysql.sock

*如果不想重新启动,那可以直接手动启动。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j.       运行客户端程序mysql,在mysql/bin目录中,测试能否连接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql> quit

Bye

*此时会出现mysql>命令提示符,可以输入sql语句,输入quit或exit退出。为了避免每次都输入mysql的全路径/usr/local/mysql/bin/mysql,可将其加入环境变量中,在/etc/profile最后加入两行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

这样就可以在shell中直接输入mysql命令来启动客户端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql>

 

 

 

 

5.       RPM安装步骤

a.       检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2.     安装MySQL的服务器端软件,注意切换到root用户:

[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm

安装完成后,安装进程会在Linux中添加一个mysql组,以及属于mysql组的用户mysql。可通过id命令查看:

[root@localhost JavaEE]#id mysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

MySQL服务器安装之后虽然配置了相关文件,但并没有自动启动mysqld服务,需自行启动:

[root@localhost JavaEE]#service mysql start

Starting MySQL.. SUCCESS!

可通过检查端口是否开启来查看MySQL是否正常启动:

[root@localhost JavaEE]#netstat -anp|grep 3306

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      34693/mysqld

c.  安装MySQL的客户端软件:

[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm

如果安装成功应该可以运行mysql命令,注意必须是mysqld服务以及开启:

[root@localhost JavaEE]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 1

Server version: 5.5.29MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql>

d.  RPM安装方式文件分布

Directory

Contents of Directory

/usr/bin

Client programs and scripts

/usr/sbin

The mysqld server

/var/lib/mysql

Log files, databases

/usr/share/info

Manual in Info format

/usr/share/man

Unix manual pages

/usr/include/mysql

Include (header) files

/usr/lib/mysql

Libraries

/usr/share/mysql

Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation

/usr/share/sql-bench

Benchmarks

 

 

安装完成后的后续配置:

一、启动mysql server
通常情况下,我们使用的启动命令是:
复制代码 代码如下:
service mysqld start

二、设置root用户和添加一些访问用户
默认安装后,mysql的root账户是没有密码的。一般为了安全,都会给root设置一个密码:
复制代码 代码如下:
mysql> update user set password=PASSWORD('123456′) where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 

三、设置用户权限
当然,mysql是提供给用户使用的,需要新增一个用户给大家使用:
复制代码 代码如下:

mysql> insert into mysql.user(Host,User,Password) values(‘localhost','admin',password(“admin”));
Query OK, 1 row affected, 3 warnings (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
现在新增了一个用户 admin/admin, 但是用户暂时还没有分配任何的权限。
复制代码 代码如下:
mysql> grant ALL on *.* to admin@”%” Identified by “admin”;
Query OK, 0 rows affected (0.00 sec)
%代表任何主机,当然也可以只赋予:select,insert,update,delete 这些操作权限:
复制代码 代码如下:
mysql> grant select,insert,update,delete on *.* to admin@”%” Identified by “admin”;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 

四、配置非本地连接访问
   默认情况下,远程用户访问本地的数据库是不背允许的,需要执行命令,赋予任何主机或相关主机访问数据的权限:
复制代码 代码如下:
   mysql> update user set host = ‘%' where user = ‘admin';
   在任何主机上都可以使用admin这个用户访问数据。
   或者:
复制代码 代码如下:
   mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root'@'%' WITH GRANT OPTION

五、备份数据或者迁移数据
     一般使用mysqldump比较方便

六、注意事项
      linux下mysql默认表名是要区分大小写的,如果需要改称不区分大小写的,需要按下面步骤修改。
1). 用root登录,修改 /etc/my.cnf
2). 在[mysqld]下加入一行: lower_case_table_names=1
3). 重新启动数据库即可   

 

重改root密码:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('11111111') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
root登录以后,SET PASSWORD = PASSWORD('11111111');

 

 windows下绿色版安装

https://www.cnblogs.com/jyiqing/p/6924062.html

 

 

 

 

posted @ 2017-06-13 10:23  malcome  阅读(109)  评论(0编辑  收藏  举报