小言_互联网的博客

Linux环境卸载安装Mysql详解

223人阅读  评论(0)

一,检查环境

      1,检查Linux环境是否已经安装了MySQL

        

       2,卸载

       

      3,再次检查发现已被删除,并检查还有没有其他的参与文件

    4,将相关的文件删除掉。至此环境已经清理干净。

二,下载安装包并安装

 

1.下载mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz的安装包

 

2.解压mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz


3.将解压的文件重命名mysql,并移动到/usr/local目录下


 
  1. # mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql

  2. # mv mysql /usr/local/


4.进入到/usr/local目录下,创建用户和用户组并授权


 
  1. # cd /usr/local/

  2. # groupadd mysql

  3. # useradd -r -g mysql mysql

  4. # cd mysql/ #注意:进入mysql文件下授权所有的文件

  5. # chown -R mysql:mysql ./ 


5.再/usr/local/mysql目录下,创建data文件夹

 

# mkdir data


6..初始化数据库,并会自动生成随机密码,记下等下登陆要用 

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


7.修改/usr/local/mysql当前目录得用户 


 
  1. # chown -R root:root ./

  2. # chown -R mysql:mysql data


8.# cp support-files/my-default.cnf /etc/my.cnf 
复制过去,其实也就是空白页,一开始没有my-default.cnf这个文件,可以用# touch my-default.cnf命令创建一个,并配置权限 
# chmod 777 ./my-default.cnf 


 


 
  1. # cd support-files/

  2. # touch my-default.cnf

  3. # chmod 777 ./my-default.cnf 

  4. # cd ../

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


9.配置my.cnf 


 
  1. # vim /etc/my.cnf 

  2. [mysqld]

  3.  

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

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

  6. # innodb_buffer_pool_size = 128M

  7.  

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

  9. # changes to the binary log between backups.

  10. # log_bin

  11.  

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

  13. basedir = /usr/local/mysql

  14. datadir = /usr/local/mysql/data

  15. socket = /tmp/mysql.sock

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

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

  18. tmpdir = /tmp

  19. port = 5186

  20. #lower_case_table_names = 1

  21. # server_id = .....

  22. # socket = .....

  23. #lower_case_table_names = 1

  24. max_allowed_packet=32M

  25. default-authentication-plugin = mysql_native_password

  26. #lower_case_file_system = on

  27. #lower_case_table_names = 1

  28. log_bin_trust_function_creators = ON

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

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

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

  32. # join_buffer_size = 128M

  33. # sort_buffer_size = 2M

  34. # read_rnd_buffer_size = 2M 

  35.  

  36. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


 

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

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

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


 
  1. # cd support-files/

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

  3. # chmod +x /etc/init.d/mysql


11.注册服务 

# chkconfig --add mysql


如果命令没有,在需要处理chkconfig


 
  1. # rpm -aq |grep chkconfig

  2. # export PATH=/sbin:$PATH

  3. # chkconfig

  4. # echo $PATH

  5. # PATH="$PATH":/sbin

  6. # echo $PATH


12.查看是否成功

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


 
  1. # vim /etc/ld.so.conf

  2.  
  3. 添加如下内容:

  4. /usr/local/mysql/lib

  5. :q


 

14.配置环境变量


 
  1. # vim /etc/profile

  2. # source /etc/profile

  3.  

  4. 添加如下内容:

  5. #MYSQL ENVIRONMENT

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


15.登陆,这里输入上面第6步随机生成得密码,细心点输入,没有显示的,登陆成功如图所示 

16.开启Navicat远程连接


 
  1. # mysql -uroot -p #进入数据库

  2. > use mysql;#进入数据库

  3. > select host, user, authentication_string, plugin from user;#查看用户信息

  4. > GRANT ALL ON *.* TO 'root'@'%';#授权root用户可以远程登陆

  5. > flush privileges;#立即生效

  6. > ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Kuaigui2019!';#修改root用户密码

  7. > FLUSH PRIVILEGES;#立即生效

  8. > exit;#退出

  9. # service mysql restart#重启mysql服务


17.navicat连接成功

 


转载:https://blog.csdn.net/m0_37253968/article/details/101272839
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场