写这个没什么意思,就是希望自己以后如果忘了能回顾一下。
域名在华为云买的,服务器腾讯云买的。为什么?因为新人便宜。。。
服务器系统是linux。项目是vue+nodejs+mysql;
域名解析,服务器备案这里不细说。

linux下搭建mysql数据库

  1. 下载mysql。下载地址:https://dev.mysql.com/downloads/mysql/5.6.html#downloads,

    三个选择,第一个mysql版本,第二个服务器系统,第三个32位还是64位(服务器购买的时候就能知道),根据需要选择,然后download。

  2. 我用的xhell+xftp连接的linux。下载xshell+xftp地址:https://www.netsarang.com/zh/xftp-download/

    选免费授权,按提示操作可免费使用。

  3. 打开xshell连接服务器,将下载的安装包放在/usr/local文件夹下,解压
    tar -zxvf mysql-5.6.40-linux-glibc2.12-i686.tar.gz

  4. 名字太长,换个名字
    mv mysql-5.6.40-linux-glibc2.12-i686 mysql
    ``

  5. 创建mysql用户组和用户
    groupadd mysql useradd -r -g mysql mysql

  6. 进入到mysql目录,添加MySQL配置
    cp support-files/my-medium.cnf /etc/my.cnf
    然后显示选择,意思是是否覆盖输入y回车选择是(n是否)

  7. 编辑/etc/my.cnf文件
    vi /etc/my.cnf

1 # For advice on how to change settings please see
2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
4 # *** default location during install, and will be replaced if you
5 # *** upgrade to a newer version of MySQL.
6 
7 [mysqld]
8 
9 # Remove leading # and set to the amount of RAM for the most important data
10 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
11 # innodb_buffer_pool_size = 128M
12 
13 # Remove leading # to turn on a very important data integrity option: logging
14 # changes to the binary log between backups.
15 # log_bin
16 
17 # These are commonly set, remove the # and set as required.
18 basedir = /usr/local/mysql
19 datadir = /usr/local/mysql/data
20 port = 3306
21 # server_id = .....
22 socket = /tmp/mysql.sock
23 character-set-server = utf8
24 skip-name-resolve
25 log-err = /usr/local/mysql/data/error.log
26 pid-file = /usr/local/mysql/data/mysql.pid
27 
28 # Remove leading # to set options mainly useful for reporting servers.
29 # The server defaults are faster for transactions and fast SELECTs.
30 # Adjust sizes as needed, experiment to find the optimal values.
31 # join_buffer_size = 128M
32 # sort_buffer_size = 2M
33 # read_rnd_buffer_size = 2M 
34 
35 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

改完按esc 然后输入:wq保存。

  1. 在mysql当前目录下设定目录的访问权限
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
  1. 初始化数据(在mysql/bin或者mysql/scripts下有个 mysql_install_db 可执行文件初始化数据库),进入mysql/bin或者mysql/scripts目录下,执行下面命令
    ./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp

  2. 启动mysql,进入/usr/local/mysql/bin目录,执行下面命令
    ./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
    如果光标停留在屏幕上,表示启动成功,然后直接关闭xshell,重新打开并连接服务器。

  3. 进入mysql目录,执行下面命令

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod 700 /etc/init.d/mysql
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /usr/local/mysql/
  1. 重启linux
    reboot
    查看mysql状态
    service mysqld status