安装包下载链接下载链接
https://dev.mysql.com/downloads/file/?id=492142
powershell
[root@localhost ~]# ls //查看压缩包
anaconda-ks.cfg Desktop Documents Downloads initial-setup-ks.cfg Music mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz Pictures Public Templates Videos
[root@localhost ~]# tar -zxf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz //解压
[root@localhost ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg mysql-5.6.47-linux-glibc2.12-x86_64 Pictures Templates
Desktop Downloads Music mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz Public Videos
[root@localhost ~]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql //移动到/usr/local/mysql
[root@localhost ~]# useradd -r -s /sbin/nologin mysql //创建系统用户
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql //更改文件拥有者
[root@localhost ~]# ls /usr/local/mysql //查看一下里面已经有东西了
bin data docs include lib LICENSE man mysql-test README scripts share sql-bench support-files
[root@localhost ~]# ll /usr/local/mysql/data //看一下还没有东西
total 0
drwxr-xr-x. 2 mysql mysql 20 Dec 5 09:54 test
[root@localhost ~]# cd /usr/local/mysql //进来这里
[root@localhost mysql]# scripts/mysql_install_db --user=mysql //初始化数据库
[root@localhost mysql]# ll data //有东西了
total 110600
-rw-rw----. 1 mysql mysql 12582912 Dec 5 10:19 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Dec 5 10:19 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Dec 5 10:19 ib_logfile1
drwx------. 2 mysql mysql 4096 Dec 5 10:19 mysql
drwx------. 2 mysql mysql 4096 Dec 5 10:19 performance_schema
drwxr-xr-x. 2 mysql mysql 20 Dec 5 09:54 test
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql //移动脚本到etc/init.d一份
[root@localhost mysql]# service mysql start //启动mysql脚本
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
SUCCESS!
[root@localhost mysql]# bin/mysqladmin -u root password '123' //设置密码
Warning: Using a password on the command line interface can be insecure.
[root@localhost mysql]# bin/mysql -u root -p //进入数据库 报错
bin/mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
[root@localhost mysql]# ln -s /lib64/libtinfo.so.6 /lib64/libtinfo.so.5 //创建软连接
[root@localhost mysql]# bin/mysql -u root -p //成功
Enter password:
[root@localhost ~]# mysql -uroot -p //返回家目录 报错 由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令
bash: mysql: command not found...
[root@localhost ~]# cd /usr/local/mysql //mysql安装在命令安装在这里的bin/mysql中
[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin //创建软连接
[root@localhost ~]# mysql -uroot -p //回到家目录,可以了
Enter password: