本文共 5191 字,大约阅读时间需要 17 分钟。
从MySQL5.5 开始就要用cmake安装,本次安装的版本为mysql-5.5.22.tar.gz
#准备工作yum install -y gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison #添加mysql用户、组groupadd mysql useradd -r -g mysql mysql mkdir /usr/local/mysql/ #创建mysql安装目录mkdir /data/mysql #创建数据存放目录#配置编译安装mysqltar zxvf mysql-5.5.13.tar.gzcd mysql-5.5.13cmake . \ #开始编译 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装到/usr/local/mysql目录 -DMYSQL_DATADIR=/data/mysql \ #数据存放到/data/mysql目录 -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \ #sock存放到/data/mysql目录 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #innoDB引擎-DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_CHARSET=utf8 \ #字符集-DDEFALUT_CHARSETS=all \ #支持所有字符集-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DDEFAULT_COLLATION=utf8_general_ci \ #字符集校验-DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DMYSQL_TCP_PORT=3306 \ -DWITH_DEBUG=0\makemake install#改变目录权限chown -R mysql /usr/local/mysqlchgrp -R mysql /usr/local/mysqlchown -R mysql /data/mysqlchgrp -R mysql /data/mysqlscripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --ldata=/data/mysql #初始化数据库chown -R root /usr/local/mysql#可选cp support-files/my-medium.cnf /etc/my.cnf #复制配置文件 cp support-files/mysql.server /etc/init.d/mysqld #复制启动脚本chmod 755 /etc/init.d/mysqld#将mysql的启动服务添加到系统服务中 chkconfig --add mysqld #添加系统服务 chkconfig mysqld on #添加开机启动chkconfig --levels 245 mysqld off或echo "/usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/data/mysql/ &" >> /etc/rc.loaclexport PATH=$PATH:/usr/local/mysql/bin #添加环境变量 echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile #启动mysqlservice mysqld start/stop 或/usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/data/mysql/ & 适用于没有自启动文件的#启动mysql,看是否成功 netstat -tnl|grep 3306
手册中提到的安装方法:
To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/local/mysql//bin/mysqladmin -u root password 'new-password'/usr/local/mysql//bin/mysqladmin -u root -h localhost password 'new-password'Alternatively you can run:/usr/local/mysql//bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/local/mysql//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/local/mysql//scripts/mysqlbug script!
默认的mysql安装目录
shell> groupadd mysqlshell> useradd -r -g mysql mysql# Beginning of source-build specific instructionsshell> tar zxvf mysql-VERSION.tar.gzshell> cd mysql-VERSIONshell> cmake .shell> makeshell> make install# End of source-build specific instructions# Postinstallation setupshell> cd /usr/local/mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql data# Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnfshell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server
修改默认密码(默认无密码):
use mysql; update user set password=password('123456') where user='root' flush privileges;
安装过程中的一些说明
To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/local/mysql//bin/mysqladmin -u root password 'new-password'/usr/local/mysql//bin/mysqladmin -u root -h localhost password 'new-password'Alternatively you can run:/usr/local/mysql//bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/local/mysql//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/local/mysql//scripts/mysqlbug script!
#mysql 默认读取配置文件 顺序/etc/my.cnf ~/.my.cnf /usr/local/mysql/etc/my.cnf
#查看编译参数sudo cat /usr/local/mysql/bin/mysqlbug|grep configure
提示mysql.sock找不到的解决
原因:
当php连接mysql时如果是本地连接(127.0.0.1 或 localhost )时,会用到 pdo_mysql.default_socket= 参数(如果是pdo连接数据库),
该默认参数为 pdo扩展编译时的参数[Pdo_mysql]; If mysqlnd is used: Number of cache slots for the internal result set cache; http://php.net/pdo_mysql.cache_sizepdo_mysql.cache_size = 2000; Default socket name for local MySQL connects. If empty, uses the built-in; MySQL defaults.; http://php.net/pdo_mysql.default-socketpdo_mysql.default_socket=
参考文章地址:
转载地址:http://mdhrj.baihongyu.com/