树莓派服务器(第十章: mysql-5.6.34 编译安装)

centos mysql-5.6.34 编译安装:

准备工作:
yum install gcc gcc-c++ ncurses-devel perl

安装cmake:
yum install cmake
或源码安装:
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz   
tar -xzvf cmake-2.8.10.2.tar.gz   
cd cmake-2.8.10.2   
./bootstrap ; make ; make install   
cd ~  

新增mysql用户组:
groupadd mysql  
新增mysql用户:
useradd -r -g mysql mysql
新建mysql安装目录:
mkdir -p /usr/local/mysql  
新建mysql数据库数据文件目录:
mkdir -p /data/mysqldb  

 wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
 tar -zxvf mysql-5.6.34.tar.gz
 cd mysql-5.6.34

从mysql5.5起,mysql源码安装开始使用cmake了,设置源码编译配置脚本:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data1/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

make -j4

make install

修改mysql目录所有者和组:
cd /usr/local/mysql   
chown -R mysql:mysql ./ 

cd /data/mysqldb  
chown -R mysql:mysql ./  

初始化mysql数据库:
cd /usr/local/mysql   
scripts/mysql_install_db –user=mysql –datadir=/data/mysqldb

复制mysql服务启动配置文件:
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf  

giedt /etc/my.cnf

[client]

port    = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]

user    = mysql
port    = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data1/mysqldb
log-error = /data/mysqldb/mysql_error.log
pid-file = /data/mysqldb/mysql.pid

复制mysql服务启动脚本及加入PATH路径:
cp support-files/mysql.server /etc/init.d/mysqld 

vim /etc/profile 

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

      export PATH

source /etc/profile  

启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的):
service mysqld start 
chkconfig –level 35 mysqld on

检查mysql服务是否启动:
netstat -tulnp | grep 3306   
mysql -u root -p   

修改MySQL用户root的密码:
mysqladmin -u root password ‘123456’

注:也可运行安全设置脚本,修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户:
/usr/local/mysql/bin/mysql_secure_installation  


MySQL问题解决:-bash:mysql:command not found  
因为mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,  
系统在/usr/bin下面查此命令,所以找不到了   
   解决办法是:  
 ln -s /usr/local/mysql/bin/mysql /usr/bin 做个链接即可 

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/usr/local/mysql/mysql.sock’ (2)
1、先查看 /etc/rc.d/init.d/mysqld status 看看mysql服务是否已经启动.
另外看看是不是权限问题.
$service mysqld start

$service mysql start
–我开始遇到的就是因为服务没启动,因为第一次玩mysql不是很熟悉,呵呵。

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

如果错啦,就修改/etc/my.cnf:

[client]

socket = /var/lib/mysql/mysql.sock

[mysqld]

socket = /var/lib/mysql/mysql.sock

3、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

[root@localhost ~]

# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]

[root@localhost ~]

# mysql -uroot -p

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
原因是,/var/lib/mysql 的访问权限问题。

shell> chown -R mysql:mysql /var/lib/mysql

接着启动服务器

shell> /etc/init.d/mysql start

服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。

4、修改/etc/my.conf:

[mysqld]

datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]

user=mysql
basedir=/usr/local/mysql

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:

[client]

socket=/var/lib/mysql/mysql.sock

如果发现问题依旧,尝试运行/etc/init.d/mysql start报错:Starting MySQLCouldn’t find MySQL manager or server

如是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &

作者:兔子ming_
来源:CSDN
原文:https://blog.csdn.net/hxmcnu/article/details/53269102
版权声明:本文为博主原创文章,转载请附上博文链接!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注