加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

linux中安装mysql数据库的2种技巧

发布时间:2022-06-11 15:50:36 所属栏目:MySql教程 来源:互联网
导读:安装mysql数据库在linux系统中有两种安装方法,一种是编译安装mysql 另一种是 免编译式安装mysql了,希望下文对各位有帮助. 编译安装mysql 安装前准备:如果mysql用户不存在,那么添加mysql用户. wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.
  安装mysql数据库在linux系统中有两种安装方法,一种是编译安装mysql 另一种是 免编译式安装mysql了,希望下文对各位有帮助.
 
  编译安装mysql
 
  安装前准备:如果mysql用户不存在,那么添加mysql用户.
 
  wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
  tar -zxvf mysql-5.1.70.tar.gz
  cd mysql-5.1.70
  yum install ncurses ncurses-devel
  ./configure  '--prefix=/usr/local/mysql' '--without-debug' '--with-charset=utf8' '--with-extra-charsets=all' '--enable-assembler' '--with-pthread' '--enable-thread-safe-client' '--with-mysqld-ldflags=-all-static' '--with-client-ldflags=-all-static' '--with-big-tables' '--with-readline' '--with-ssl' '--with-embedded-server' '--enable-local-infile' '--with-plugins=innobase'
  make
  make install
  到此mysql就安装到了/usr/local/mysql路径下,下面开始mysql的配置工作.
 
  /usr/local/mysql/bin/mysql_install_db --user=mysql
 
  启动mysql:/etc/init.d/mysqld start
 
  这一步可能会报错:
 
  /etc/init.d/mysqld: line 260: my_print_defaults: command not found
  /etc/init.d/mysqld: line 263: my_print_defaults: command not found
  /etc/init.d/mysqld: line 270: @HOSTNAME@: command not found
  /etc/init.d/mysqld: line 279: @HOSTNAME@: command not found
  /etc/init.d/mysqld: line 292: cd: @prefix@: No such file or directory
  Starting MySQLCouldn't find MySQL manager (@bindir@/mysqlmanager) or server (@bindir@/mysqld_safe) [FAILED]  --phpfensi.com
  因为路径没有设置,请重启确认上面配置工作是否都完成,一般是configure后没有make和make install.
 
  mysql初始化配置:
 
  export PATH=/usr/local/mysql/bin:$PATH
 
  make[2]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
  make[3]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
  make[3]: Nothing to be done for `install-exec-am.
  make INSTALL_TO_DIR="/usr/local/mysql/mysql-test" install_test_files
  make[4]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
  时间较长:MYSQL安装到这里卡了很久,可能以为出错了,实际上MYSQL已经安装成功了,它这步过段时间就会好了,是mysql在自我编译测试造成的.
 
  2.checking for termcap functions library... configure: error: No curses/termcap library found
 
  yum install ncurses ncurses-devel
 
  3.Starting MySQL.Manager of pid-file quit without updating fi[FAILED]
 
  启动数据库之前,需要先配置权限表,其中/usr/local/mysql为mysql的安装目录.
 
  chown -R mysql:mysql /usr/local/mysql
 
  /usr/local/mysql/bin/mysql_install_db --user=mysql
 
  上面安装mysql是通过编译的方式安装,此次不进行编译,直接安装.
 
  [root@hk tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
  [root@hk tools]# tar zxf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
   [root@hk opt]# /usr/sbin/useradd mysql -s /sbin/nologin -M
  [root@hk opt]# cd mysql/
  [root@hk mysql]# /opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql/ --datadir=/opt/mysql/data --user=mysql  
  [root@hk mysql]# mv /etc/my.cnf /etc/my.cnf.backup
  [root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf  
  [root@hk mysql]# cp /opt/mysql/my.cnf /etc/my.cnf
  [root@hk mysql]# /opt/mysql/support-files/mysql.server start
  [root@hk mysql]# netstat -tunlp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name    
  tcp        0      0 :::3306                     :::*                        LISTEN      28104/mysqld   
  [root@hk mysql]#  /opt/mysql/bin/mysql -uroot -p
  Enter password:  
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) #看下面的sock的配置
  [root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf  
  [root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
  Enter password:  
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)   #居 
  mysql> flush privileges;
  [root@hk mysql]# skill 30194
  [root@hk mysql]# 140601 00:14:38 mysqld_safe mysqld from pid file /opt/mysql/data/hk.t4x.org.pid ended
  [1]+  Done                    /opt/mysql/bin/mysqld_safe --skip-grant-tables
  [root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
  Enter password:  
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)    #错误依旧
  [root@hk mysql]# vim /usr/local/mysql/support-files/mysql.server   #配置文件中默认配置目录是/usr/local/mysql
  [root@hk mysql]# ln -s /opt/mysql /usr/local/mysql    #设置软连接
  [root@hk mysql]# /usr/local/mysql/bin/mysql -uroot -p'admin123'
  mysql>

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读