Linux下安装MySql数据库

时间:2022-02-04 09:19:34
before install mysql, please install cmake
1. download cmake-3.0.1.tar.gz


2. ./configure


3. gmake


4. sudo make install


before install mysql, please install ncurses
1. download ncurses-5.6.tar.gz


2. ./configure


3. make


4. sudo make install




1.mysql-5.5.39
  tar zxvf mysql-5.5.39.tar.gz


2.cd mysql-5.5.39


3.cmake
  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci


4.make
  make


5.install(please add sudo)
  sudo make install


6.cd /usr/local/mysql/support-files/


7.sudo cp my-medium.cnf /etc/my.cnf








mysql-connector-odbc-5.1.13-src.tar.gz安装(源码编译将mysql生成对应so文件,我们使用的是mysql5系列,所以这里对应生成libmyodbc5.so)
运行mysql-connecotr-odbc生成libmyodbc5.so(针对mysql5)
1.下载 mysql-connector-odbc-5.1.13-src.tar.gz
2.解压
3.cmake安装,注意配置的是数据库信息
  cmake -G "Unix Makefiles" -DMYSQL_DIR=/usr/local/mysql -DMYSQL_INCLUDE_DIR=/usr/local/mysql/include -DMYSQL_LIB_DIR=/usr/local/mysql/lib -DWITH_UNIXODBC=1
4.make
  make
5.install
  sudo make install






参考:
http://blog.sina.com.cn/s/blog_6d39ac7e0101cq48.html
http://wenku.baidu.com/link?url=tMqvlIkD-9J47xpEDRNTl8jwhx8WKltmo5rv3r7mAliIfdXRYCJUkt7uezFrX8qekKLbLbgAt8lKyl4Vh8cFEC01PCt2UDnLVTkqAhYQ3ry










注意事项:
1.安装mysql,虚拟机情况不能再windows共享目录下make,出现CMake Error: cmake_symlink_library: System Error: Operation not supported错误


2.mysql-connector-odbc-5.1.13-src.tar.gz安装时报错如下:
[ 50%] Building C object installer/CMakeFiles/myodbc-installer.dir/myodbc3i.c.o
Linking C executable ../bin/myodbc-installer
/usr/bin/ld: /usr/local/mysql/lib/libmysqlclient.a(my_thr_init.c.o): undefined reference to symbol 'pthread_create@@GLIBC_2.1'
/usr/bin/ld: note: 'pthread_create@@GLIBC_2.1' is defined in DSO /lib/libpthread.so.0 so try adding it to the linker command line
/lib/libpthread.so.0: could not read symbols: 无效的操作
collect2: 错误:ld 返回 1
make[2]: *** [bin/myodbc-installer] 错误 1
make[1]: *** [installer/CMakeFiles/myodbc-installer.dir/all] 错误 2
make: *** [all] 错误 2


解决:
打开mysql-connector-odbc-5.1.13-src目录的makefile文件,查找myodbc-installer,结果如下:
# Build rule for target.
myodbc-installer: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 myodbc-installer
.PHONY : myodbc-installer


# fast build rule for target.
myodbc-installer/fast:
$(MAKE) -f installer/CMakeFiles/myodbc-installer.dir/build.make installer/CMakeFiles/myodbc-installer.dir/build
.PHONY : myodbc-installer/fast


可以看到$(MAKE) -f installer/CMakeFiles/myodbc-installer.dir/build.make表示执行myodbc-installer时用到了mysql-connector-odbc-5.1.13-src/installer/CMakeFiles/myodbc-installer.dir目录的build.make文件,
而build.make文件又使用了link.txt文件,打开link.txt文件,加入 -lpthread 链接


myodbc-installer问题解决后,继续编译my_basics也发生类似错误,按如上方法,修改mysql-connector-odbc-5.1.13-src/test/CMakeFiles/my_basics.dir/link.txt文件,加入 -lpthread 链接
link.txt文件修改后如下:
/usr/lib/ccache/cc      -L/usr/lib32 -lodbc   CMakeFiles/my_basics.dir/my_basics.c.o  -o my_basics  -L/usr/local/mysql/lib -rdynamic -L/usr/lib32 -lodbc -lodbcinst -lpthread -Wl,-rpath,/usr/local/mysql/lib: 


mysql数据库配置:

1.安装mysql
2.数据库安装完成后,进入/usr/sbin
3.创建用户和组(注意groupadd与useradd命令均在/usr/sbin文件夹下)
sudo groupadd mysql
sudo useradd -g mysql mysql
4、修改目录拥有者
cd /usr/local/mysql/
sudo chown -R mysql /usr/local/mysql/.
sudo chgrp -R mysql /usr/local/mysql/.
5、初始化数据库
sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
6、启动
bin/mysqld_safe &
(若此处执行提示错误,有可能是/etc/my.cnf配置有误,一般情况下删除即可,或者通过复制mysql安装时自带的配置文件模板替换,如:cp /usr/local/mysql/support-files/my-huge.cnf  /etc/my.cnf)
7、初始化root密码
bin/mysqladmin -u root password 'password'
注意:'password'是登录时的密码
修改密码:
cd /usr/local/mysql/bin
./mysql -uroot -p
set password for 'root'@'localhost'=password('newPasswd'); 
8、登录数据库
bin/mysql -uroot -p
输入密码进入数据库
9、查看
Mysql> show databases;
OK!
开户/关闭mysql 服务
输入 find / -name mysql.server找到这个文件后,复制到 /etc/init.d and 并重命名为mysql,然后就可以使用
 /etc/init.d/mysql start " 来启动mysql服务.
/etc/init.d/mysql stop " 来关闭mysql服务.


10.给本机mysql设置可被访问的权限
进入mysql界面后输入以下语句,红色标明处分是连接mysql时需要输入的用户名(此处为root)及密码(此处为123456),依实际需要修改。
  mysql> use mysql;
  mysql> grant all privileges on *.* to root@'%' identified by '123456';
  mysql>flush privileges;
  mysql> quit;
  退出界面,所有操作完毕,现在可通过上面设置的用户名及密码访问本机mysql数据库了,连接时请关闭防火墙。




安装时用到的相关源码我已上传,请到这里下载:

http://download.csdn.net/detail/liuguangzhou123/8435475