MySql数据库服务器的启动和关闭

 由于刚刚考完试,今天从下午2点开始到晚上9点,真是要命,看来大四了就是不一样,不过过程很完美!就是说有点累,所以就打开浙大的一个老师的MySql数据库教程,这几天一直想看看这个数据库的优点到底在哪里?不过就是我要开始的时候却遇到一个郁闷的事,在关闭了MySql的服务器后不知道怎么的就不能再连接上了?

最后,我上CSDN上找一篇文章,不过还是没看懂,最后自己结合教程和MySql的帮助文档,终于连接成功!

下面就把我这次的收获同大家一起分享:

首先是如何去启动一个MySql的服务器,因为我的MySql是装在C:/Program files/mysql/mysql server 5.0目录下

首先打开命令提示符 在运行-->输入cmd;

然后依次进入如下目录:

C:/>cd Program Files

C:/Program Files>cd mysql

C:/Program Files/MySQL>cd mysql server 5.0

C:/Program Files/MySQL/MySQL Server 5.0>cd bin

C:/Program Files/MySQL/MySQL Server 5.0/bin>

下面来看一下如何去连接MySql服务器:

C:/Program Files/MySQL/MySQL Server 5.0/bin>mysql -h localhost -u root -p

password:****

然后成功连接上服务器!

结果显示如下:

C:/Program Files/MySQL/MySQL Server 5.0/bin>mysql -h localhost -u root  -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2 to server version: 5.0.18

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql>

 

下面再看一下关闭MySql服务器的代码:

先退出MYSQL

mysql>quit

bye

 

C:/Program Files/MySQL/MySQL Server 5.0/bin>mysql -h localhost -u root  -p123 shutdown

就OK了,好了今天就到这里,SQL Server用习惯了,实在没办法这么快理解命令行的操作!还好,现在慢慢适应了!


发布了17 篇原创文章 · 获赞 0 · 访问量 4万+
展开阅读全文

关于连接服务器MySql数据库,却不能成功打开

03-28

namespace Lode { class Program { static void Main(string[] args) { string load, password; load = Console.ReadLine(); password = Console.ReadLine(); if (Search(load,password)) { Console.WriteLine("登入成功"); } else Console.WriteLine("登入失败"); } /// <summary> /// 建立执行命令语句对象 /// </summary> /// <param name="sql"></param> /// <param name="mysql"></param> /// <returns></returns> public static MySqlCommand getSqlCommand(String sql, MySqlConnection mysql) { MySqlCommand mySqlCommand = new MySqlCommand(sql, mysql); // MySqlCommand mySqlCommand = new MySqlCommand(sql); // mySqlCommand.Connection = mysql; return mySqlCommand; } /// <summary> /// 查询并获得结果集并遍历 /// </summary> /// <param name="mySqlCommand"></param> public static bool Search(string load,string password ) { /* //连接数据库 //server=这里写服务器的IP地址;uid=数据登录名;pwd=密码;database=数据库 String mysqlStr = @"Database=bbs;Data Source=59.74.169.59;User Id=bbs;Password=kjcxlab.com!@!@;pooling=false;CharSet=utf8;port=8080"; // String mySqlCon = ConfigurationManager.ConnectionStrings["MySqlCon"].ConnectionString; */ MySqlConnection mysql = getMySqlcon(); int i = 0; Console.WriteLine("46"); try { Console.WriteLine("56"); if (mysql.State == ConnectionState.Open) //检查连接状态 { mysql.Close(); } Console.WriteLine("63"); mysql.Open(); //打开数据库连接 string sqlSearch; Console.WriteLine("64"); if (IsEmail(load)) { sqlSearch = @"select * from bbs_common_member where email='" + load + "' AND password=MD5('" + password + "')"; } else { sqlSearch = @"select * from data where username='" + load + "' AND password=MD5('" + password + "')"; } MySqlCommand mySqlCommand = getSqlCommand(sqlSearch, mysql); i = Convert.ToInt32(mySqlCommand.ExecuteScalar()); } catch (MySqlException oe) { Console.WriteLine(oe.Message); } finally { if (mysql.State == ConnectionState.Open) mysql.Close(); } if (i != 1) { return false; } else return true; } /// <summary> /// 建立mysql数据库链接 /// </summary> /// <returns></returns> private static MySqlConnection getMySqlcon() { //server=这里写服务器的IP地址;uid=数据登录名;pwd=密码;database=数据库 String mysqlStr = @"Database=bbs;Data Source=59.74.169.59;User Id=bbs;Password=kjcxlab.com!@!@;pooling=false;CharSet=utf8;Port=8080"; //String mySqlCon = ConfigurationManager.ConnectionStrings["MySqlCon"].ConnectionString; MySqlConnection mysql = new MySqlConnection(mysqlStr); return mysql; } public static bool IsEmail(string str) { string res = string.Empty; string expression = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; bool boo = new Regex(expression).Match(str).Success; return boo; } } } ``` ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览