mysql刷新命令(mysql安装及配置超详细教程)

mysql刷新命令(mysql安装及配置超详细教程)

MySQL安装教程

一、Windows安装步骤

一、下载MySQL

首先,去数据库的官网http://www.mysql.com下载MySQL。

二、安装MySQL

打开刚刚下载好的安装包,开始安装MySQL。

安装完成后进入MySQL的安装目录,进入MySQL Sever,其目录下的文件如下:


bin目录下保存了MySQL常用的命令工具以及管理工具、data目录是MySQL默认用来保存数据文件以及日志文件的地方(我的因刚安装还没有data文件夹)、docs目录下是MySQL的帮助文档、include目录和lib目录是MySQL所依赖的头文件以及库文件、share目录下保存目录文件以及日志文件。

二、linux安装步骤

2、我这里通过xftp将安装包上传至Linux服务器

3.解压

解压命令:tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar

继续解压需要的那一个

命令:tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

重命名并移动到合适的路径

重命名 :mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql

移动:

4.在/usr/local/mysql下创建data文件夹

1

# mkdir data

5.初始化数据库,自动生成密码 需记录 等下要用

# bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

ps:中间遇到一个坑,初始化数据库时候报了错

具体错误为:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决方法为:yum install libaio-devel.x86_64 原因是缺少了libaio这个东西 安装就完事了

再次执行初始化命令

得到初始化密码,需要记下,一会会用到

6.修改/usr/local/mysql 当前目录的用户

1

2

# chown -R root:root ./

# chown -R mysql:mysql data

7.复制my-default.cnf这个文件到etc/my.cnf去

具体命令为:

1

2

3

4

5

# cd support-files/

# touch my-default.cnf

# chmod 777 ./my-default.cnf

# cd ../

# cp support-files/my-default.cnf /etc/my.cnf

8.完了之后配置my.cnf

1

vim /etc/my.cnf

内容:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

socket = /tmp/mysql.sock

log-error = /usr/local/mysql/data/error.log

pid-file = /usr/local/mysql/data/mysql.pid

tmpdir = /tmp

port = 5186

#lower_case_table_names = 1

# server_id = …..

# socket = …..

#lower_case_table_names = 1

max_allowed_packet=32M

default-authentication-plugin = mysql_native_password

#lower_case_file_system = on

#lower_case_table_names = 1

log_bin_trust_function_creators = ON

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

如果后期mysql运行报错,可以直接到log-error = /usr/local/mysql/data/error.log目录下直接查看错误日志

命令:cat /usr/local/mysql/data/error.log

9.开机自启,进入/usr/local/mysql/support-files进行设置

1

2

3

# cd support-files/

# cp mysql.server /etc/init.d/mysql

# chmod x /etc/init.d/mysql

10.注册服务

1

# chkconfig –add mysql

11.查看是否成功

12.etc/ld.so.conf要配置路径,不然报错

1

# vim /etc/ld.so.conf

添加如下内容:

1

/usr/local/mysql/lib

13.配置环境变量

1

2

# vim /etc/profile

# source /etc/profile

添加如下内容:

1

2

#MYSQL ENVIRONMENT

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

14.登录 需要用到上面的生成的密码

1

2

3

4

5

6

7

8

9

10

#启动mysql服务

[root@localhost bin]# service mysql start

Starting MySQL.Logging to ‘/usr/local/mysql/data/error.log’.

.. SUCCESS!

[root@localhost bin]#

#修改mysql密码

mysql> alter user ‘root’@’localhost’ identified by ‘123456’;

Query OK, 0 rows affected (0.02 sec)

mysql>

ps:第二个坑,在启动时出现错误 详情为:Starting MySQL…The server quit without updating PID file [FAILED]cal/mysql/data/mysql.pid).

该错误翻了一下午,绕了一大圈,最终问题是my.cnf文件配置问题,千万不能以为加了#就是注释掉了,自己检查了n遍,觉得没有错,结果就是不行,没有办法找了一份另一台服务器的my.cnf配置,复制替换稍加修改,解决问题。

大功告成!可以使用可视化工具进行数据库连接了。

安装完成。

END

发表评论

登录后才能评论